|
| 1 | +name: Update SPDX licenses |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * *" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token |
| 13 | +permissions: { } |
| 14 | + |
| 15 | +jobs: |
| 16 | + update: |
| 17 | + name: Update Schemas |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + changed: ${{ steps.diff.outputs.changed }} |
| 21 | + version: ${{ steps.version.outputs.version }} |
| 22 | + timeout-minutes: 10 |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + # see https://github.com/actions/checkout |
| 26 | + uses: actions/checkout@v5 |
| 27 | + with: |
| 28 | + ref: ${{ github.ref_name }} |
| 29 | + - name: Set up JDK |
| 30 | + # see https://github.com/actions/setup-java |
| 31 | + uses: actions/setup-java@v5 |
| 32 | + with: |
| 33 | + java-version: '21' |
| 34 | + distribution: 'zulu' |
| 35 | + java-package: jdk |
| 36 | + - name: Update SPDX |
| 37 | + run: tools/updateSpdx.sh |
| 38 | + - name: detect version |
| 39 | + id: version |
| 40 | + run: | |
| 41 | + value=$( jq -r '.["$comment"]' schema/spdx.schema.json ) |
| 42 | + echo "version=$value" >> $GITHUB_OUTPUT |
| 43 | + - name: Detect changes |
| 44 | + id: diff |
| 45 | + run: | |
| 46 | + if git diff --quiet -- 'schema/spdx.*' |
| 47 | + then |
| 48 | + echo "$GITHUB_REF_NAME is up-to-date" |
| 49 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 50 | + else |
| 51 | + echo "$GITHUB_REF_NAME is not up-to-date" |
| 52 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 53 | + fi |
| 54 | + - name: Artifact changes |
| 55 | + if: ${{ steps.diff.outputs.changed == 'true' }} |
| 56 | + # https://github.com/actions/upload-artifact |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + retention-days: 1 |
| 60 | + name: schema-spdx |
| 61 | + path: schema/spdx.* |
| 62 | + if-no-files-found: error |
| 63 | + pullrequest: |
| 64 | + name: Pull-request Changes |
| 65 | + runs-on: ubuntu-latest |
| 66 | + needs: [ 'update' ] |
| 67 | + if: ${{ needs.update.outputs.changed == 'true' }} |
| 68 | + permissions: |
| 69 | + contents: write # push commits |
| 70 | + pull-requests: write # create pullrequests |
| 71 | + env: |
| 72 | + SB_VERSION: ${{ needs.update.outputs.version }} |
| 73 | + SB_BRANCH: ${{ github.ref_name }}_update-spdx/${{ needs.update.outputs.version }} |
| 74 | + steps: |
| 75 | + - name: Checkout |
| 76 | + # see https://github.com/actions/checkout |
| 77 | + uses: actions/checkout@v5 |
| 78 | + with: |
| 79 | + ref: ${{ github.ref_name }} |
| 80 | + - name: Switch branch |
| 81 | + id: branch |
| 82 | + run: | |
| 83 | + set -eux |
| 84 | + git remote set-branches origin "$SB_BRANCH" |
| 85 | + if git ls-remote --exit-code --heads origin "$SB_BRANCH" |
| 86 | + then |
| 87 | + echo "existed=true" >> $GITHUB_OUTPUT |
| 88 | + git fetch --depth=1 origin "$SB_BRANCH" |
| 89 | + git checkout -b "$SB_BRANCH" "origin/$SB_BRANCH" |
| 90 | + else |
| 91 | + echo "existed=false" >> $GITHUB_OUTPUT |
| 92 | + git checkout -b "$SB_BRANCH" |
| 93 | + fi |
| 94 | + - name: Fetch changes |
| 95 | + # https://github.com/actions/download-artifact |
| 96 | + uses: actions/download-artifact@v5 |
| 97 | + with: |
| 98 | + name: schema-spdx |
| 99 | + path: schema |
| 100 | + - name: Commit and push |
| 101 | + run: | |
| 102 | + set -eux |
| 103 | + if git diff --quiet -- 'schema/spdx.*' |
| 104 | + then |
| 105 | + echo "branch up-to-date" |
| 106 | + exit 0 |
| 107 | + fi |
| 108 | + git config user.name 'spdx-license-bumper[bot]' |
| 109 | + git config user.email 'spdx-license-bumper@bot.local' |
| 110 | + git add -A schema |
| 111 | + git commit -s -m "feat: bump SPDX licenses $SB_VERSION" |
| 112 | + git push origin "$SB_BRANCH" |
| 113 | + - name: Pull request |
| 114 | + if: ${{ steps.branch.outputs.existed == 'false' }} |
| 115 | + run: > |
| 116 | + gh pr create |
| 117 | + --title "feat: bump SPDX Licenses $SB_VERSION" |
| 118 | + --body "$SB_VERSION" |
| 119 | + --base "$GITHUB_REF_NAME" |
| 120 | + --head "$SB_BRANCH" |
| 121 | + env: |
| 122 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments