|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2024 The Stdlib Authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +#/ |
| 18 | + |
| 19 | +# Workflow name: |
| 20 | +name: update_pr_copyright_years |
| 21 | + |
| 22 | +# Workflow triggers: |
| 23 | +on: |
| 24 | + |
| 25 | + # Allow the workflow to be triggered by other workflows |
| 26 | + workflow_call: |
| 27 | + |
| 28 | +# Workflow jobs: |
| 29 | +jobs: |
| 30 | + |
| 31 | + # Define a job for updating the copyright years: |
| 32 | + update: |
| 33 | + |
| 34 | + # Define a display name: |
| 35 | + name: 'Update Copyright Years' |
| 36 | + |
| 37 | + # Define the type of virtual host machine: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + |
| 40 | + # Define the sequence of job steps... |
| 41 | + steps: |
| 42 | + |
| 43 | + # Checkout the repository: |
| 44 | + - name: 'Checkout repository' |
| 45 | + # Pin action to full length commit SHA |
| 46 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 47 | + with: |
| 48 | + # Refers to the branch name of the branch being pushed: |
| 49 | + ref: ${{ github.event.pull_request.head.ref }} |
| 50 | + |
| 51 | + # Token for accessing the repository: |
| 52 | + token: ${{ secrets.REPO_GITHUB_TOKEN }} |
| 53 | + |
| 54 | + # Get list of changed files: |
| 55 | + - name: 'Get list of changed files' |
| 56 | + id: changed-files |
| 57 | + continue-on-error: true |
| 58 | + 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 }}) |
| 62 | + echo "files=${files}" >> $GITHUB_OUTPUT |
| 63 | +
|
| 64 | + # Update the copyright years: |
| 65 | + - name: 'Update copyright years' |
| 66 | + id: update-years |
| 67 | + run: | |
| 68 | + files="{{ steps.changed-files.outputs.files }}" |
| 69 | + . "$GITHUB_WORKSPACE/.github/workflows/scripts/update_copyright_years" $files |
| 70 | +
|
| 71 | + # Disable Git hooks: |
| 72 | + - name: 'Disable Git hooks' |
| 73 | + run: | |
| 74 | + rm -rf .git/hooks |
| 75 | +
|
| 76 | + # Import GPG key to sign commits: |
| 77 | + - name: 'Import GPG key to sign commits' |
| 78 | + # Pin action to full length commit SHA |
| 79 | + uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 |
| 80 | + with: |
| 81 | + gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }} |
| 82 | + passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }} |
| 83 | + git_user_signingkey: true |
| 84 | + git_commit_gpgsign: true |
| 85 | + |
| 86 | + # Commit and push changes: |
| 87 | + - name: 'Commit and push changes' |
| 88 | + env: |
| 89 | + REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} |
| 90 | + USER_NAME: stdlb-bot |
| 91 | + BRANCH_NAME: ${{ github.event.pull_request.head.ref }} |
| 92 | + run: | |
| 93 | + git config --local user.email "82920195+stdlib-bot@users.noreply.github.com" |
| 94 | + git config --local user.name "stdlib-bot" |
| 95 | + git add . |
| 96 | + git commit -m "chore: update copyright years" |
| 97 | + git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/stdlib-js/stdlib.git" $BRANCH_NAME |
0 commit comments