2424
2525 # Allow the workflow to be triggered by other workflows
2626 workflow_call :
27+ # Define the input parameters for the workflow:
28+ inputs :
29+ pull_request_number :
30+ description : ' PR number'
31+ required : true
32+ type : number
33+ repository :
34+ description : ' Repository name'
35+ required : true
36+ type : string
37+ branch :
38+ description : ' PR branch name'
39+ required : true
40+ type : string
41+ # Define the secrets accessible by the workflow:
42+ secrets :
43+ STDLIB_BOT_GITHUB_TOKEN :
44+ description : ' GitHub token for stdlb-bot'
45+ required : true
46+ REPO_GITHUB_TOKEN :
47+ description : ' GitHub token for accessing the repository'
48+ required : true
49+ STDLIB_BOT_GPG_PRIVATE_KEY :
50+ description : ' GPG private key for stdlb-bot'
51+ required : true
52+ STDLIB_BOT_GPG_PASSPHRASE :
53+ description : ' GPG passphrase for stdlb-bot'
54+ required : true
2755
2856# Workflow jobs:
2957jobs :
@@ -46,26 +74,37 @@ jobs:
4674 uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4775 with :
4876 # Refers to the branch name of the branch being pushed:
49- ref : ${{ github.event.pull_request.head.ref }}
77+ ref : ${{ inputs.branch }}
78+
79+ # Refers to the repository name:
80+ repository : ${{ inputs.repository }}
5081
5182 # Token for accessing the repository:
5283 token : ${{ secrets.REPO_GITHUB_TOKEN }}
5384
54- # Get list of changed files:
55- - name : ' Get list of changed files'
56- id : changed-files
57- continue-on-error : true
85+ # Get list of added files:
86+ - name : ' Get list of added files'
87+ id : added-files
5888 run : |
59- # Get the list of changed files in pull request:
60- ancestor_commit=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
61- files=$(git diff --diff-filter=AM --name-only $ancestor_commit ${{ github.event.pull_request.head.sha }})
89+ page=1
90+ files=""
91+ while true; do
92+ new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN
93+ }}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
94+ if [ -z "$new_files" ]; then
95+ break
96+ fi
97+ files="$files $new_files"
98+ page=$((page+1))
99+ done
100+ files=$(echo "$files" | tr '\n' ' ' | sed 's/ $//')
62101 echo "files=${files}" >> $GITHUB_OUTPUT
63102
64103 # Update the copyright years:
65104 - name : ' Update copyright years'
66105 id : update-years
67106 run : |
68- files="{{ steps.changed -files.outputs.files }}"
107+ files="{{ steps.added -files.outputs.files }}"
69108 . "$GITHUB_WORKSPACE/.github/workflows/scripts/update_copyright_years" $files
70109
71110 # Disable Git hooks:
@@ -88,10 +127,11 @@ jobs:
88127 env :
89128 REPO_GITHUB_TOKEN : ${{ secrets.REPO_GITHUB_TOKEN }}
90129 USER_NAME : stdlb-bot
91- BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
130+ BRANCH_NAME : ${{ inputs.branch }}
131+ REPO_NAME : ${{ inputs.repository }}
92132 run : |
93133 git config --local user.email "82920195+stdlib-bot@users.noreply.github.com"
94134 git config --local user.name "stdlib-bot"
95135 git add .
96136 git commit -m "chore: update copyright years"
97- git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/stdlib-js/stdlib .git" $BRANCH_NAME
137+ git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/$REPO_NAME .git" $BRANCH_NAME
0 commit comments