-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (92 loc) · 4.28 KB
/
internal-commit-results.yml
File metadata and controls
102 lines (92 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Commit Results
on:
workflow_call:
inputs:
commit-author-name:
description: "The display name of the commit author"
required: false
type: string
default: '${{ github.event.repository.name }} Continuous Integration'
commit-author-email:
description: "The email address of the commit author"
required: true
type: string
commit-message:
description: "The commit message"
required: false
type: string
default: "ci: Add automated results"
commit-directory:
description: "The directory where the artifacts will be downloaded and committed"
required: true
type: string
second-commit-directory:
description: "An optional second directory where the same files will be copied and committed"
required: false
type: string
default: ""
file-filter:
description: "A filter to apply to files in the commit-directory when staging them with git add. Example: *.md"
required: false
type: string
default: ""
uploaded-artifact-name:
description: "The name of the uploaded artifact"
required: true
type: string
secrets:
repository-commit-token:
description: "The token to use for committing to the repository"
required: true
jobs:
commit-results:
runs-on: ubuntu-latest
steps:
- name: Checkout GIT Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.repository-commit-token }}
- name: Download artifacts to commit
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: ${{ inputs.uploaded-artifact-name }}
path: ${{ inputs.commit-directory }}
- name: Copy artifacts into the second directory
if: inputs.second-commit-directory != ''
run: rm -rf ${{ inputs.second-commit-directory }} && cp -r ${{ inputs.commit-directory }} ${{ inputs.second-commit-directory }}
- name: Display environment variable "github.event_name"
run: echo "github.event_name=${{ github.event_name }}"
- name: Assemble GIT_ADD_PATH
run: echo "GIT_ADD_PATH=${{ inputs.commit-directory }}${{ inputs.file-filter != '' && '/' || '' }}${{ inputs.file-filter }}" >> $GITHUB_ENV
- name: Display GIT_ADD_PATH
run: echo "GIT_ADD_PATH=${{ env.GIT_ADD_PATH }}"
- name: Assemble SECOND_GIT_ADD_PATH
if: inputs.second-commit-directory != ''
run: echo "SECOND_GIT_ADD_PATH=${{ inputs.second-commit-directory }}${{ inputs.file-filter != '' && '/' || '' }}${{ inputs.file-filter }}" >> $GITHUB_ENV
- name: Display SECOND_GIT_ADD_PATH
if: inputs.second-commit-directory != ''
run: echo "SECOND_GIT_ADD_PATH=${{ env.SECOND_GIT_ADD_PATH }}"
- name: Prepare commit of changes in `${{ inputs.commit-directory }}`
run: |
set -x # Print commands and their arguments as they are executed
git config --global user.name '${{ inputs.commit-author-name }}'
git config --global user.email '${{ inputs.commit-author-email }}'
git config --local http.postBuffer 524288000
git fetch origin
git status
git add ${{ env.GIT_ADD_PATH }} ${{ env.SECOND_GIT_ADD_PATH }}
git status
- name: Commit and push changes in `${{ inputs.commit-directory }}`
# Only run when a pull request gets merged or a commit is pushed to the main branch
if: github.event_name == 'push'
run: |
set -x # Print commands and their arguments as they are executed
git commit --message "${{ inputs.commit-message }}"
git status
git rebase --strategy-option=theirs origin/main --verbose # Resolve conflicts by taking the current branch's changes
git add ${{ env.GIT_ADD_PATH }} ${{ env.SECOND_GIT_ADD_PATH }} # Add the files again after the rebase
GIT_EDITOR=true git rebase --continue || true # Continue the rebase or ignore if it fails
git status
git commit --amend --no-edit # Amend the commit to include the changes from the rebase
git status
git push --verbose