55 - cron : " 0 0 * * *"
66 workflow_dispatch :
77
8+ concurrency :
9+ group : ${{ github.workflow }}-${{ github.ref }}
10+ cancel-in-progress : true
11+
812# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token
9- permissions : {}
13+ permissions : { }
1014
1115jobs :
1216 update :
17+ name : Update Schemas
1318 runs-on : ubuntu-latest
19+ outputs :
20+ changed : ${{ steps.diff.outputs.changed }}
21+ version : ${{ steps.version.outputs.version }}
22+ timeout-minutes : 10
1423 steps :
1524 - name : Checkout
1625 # see https://github.com/actions/checkout
1726 uses : actions/checkout@v5
27+ with :
28+ ref : ${{ github.ref_name }}
1829 - name : Set up JDK
1930 # see https://github.com/actions/setup-java
2031 uses : actions/setup-java@v5
@@ -24,18 +35,78 @@ jobs:
2435 java-package : jdk
2536 - name : update
2637 run : tools/updateSpdx.sh
27- - name : Archive Schema
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 "changed=false" >> $GITHUB_OUTPUT
49+ else
50+ echo "changed=true" >> $GITHUB_OUTPUT
51+ fi
52+ - name : Artifact changes
53+ if : ${{ steps.diff.outputs.changed == 'true' }}
2854 # https://github.com/actions/upload-artifact
2955 uses : actions/upload-artifact@v4
3056 with :
31- name : schema
57+ retention-days : 1
58+ name : schema-spdx
3259 path : schema/spdx.*
3360 if-no-files-found : error
34- # TODO:
35- # - if no changes: abort; else:
36- # - detect version - pull from JSON `$comment`
37- # - commit the changes
38- # - with message `bump SPDX licenses $version`
39- # - to branch 'spdx-licenses/$version'
40- # - signed as bot
41- # - create pullresquest
61+ pullrequest :
62+ name : Pull-request Changes
63+ runs-on : ubuntu-latest
64+ needs : ' update'
65+ if : ${{ needs.update.outputs.changed == 'true' }}
66+ permissions :
67+ contents : write # for git-push
68+ env :
69+ SB_VERSION : ${{ needs.update.outputs.version }}
70+ SB_BRANCH : spdx-schema-bump/${{ github.ref_name }}_${{ needs.update.outputs.version }}
71+ steps :
72+ - name : Checkout
73+ # see https://github.com/actions/checkout
74+ uses : actions/checkout@v5
75+ with :
76+ ref : ${{ github.ref_name }}
77+ - name : Fetch changes
78+ # https://github.com/actions/download-artifact
79+ uses : actions/download-artifact@v5
80+ with :
81+ name : schema-spdx
82+ path : schema
83+ - name : switch branch
84+ id : branch
85+ run : |
86+ set -eux
87+ git remote set-branches origin "$SB_BRANCH"
88+ if git ls-remote --exit-code --heads origin "$SB_BRANCH"
89+ then
90+ echo "existed=true" >> $GITHUB_OUTPUT
91+ git fetch --depth=1 origin "$SB_BRANCH"
92+ git checkout -b "$SB_BRANCH" "origin/$SB_BRANCH"
93+ else
94+ echo "existed=false" >> $GITHUB_OUTPUT
95+ git checkout -b "$SB_BRANCH"
96+ fi
97+ - name : configure git author
98+ run : |
99+ git config user.name "spdx-license-bumber[bot]"
100+ git config user.email "spdx-license-bumber[bot]@users.noreply.github.com"
101+ - name : commit and push changes
102+ run : |
103+ set -eux
104+ if git commit -sam "feat: bump SPDX licenses $SB_VERSION"
105+ then
106+ git push origin "$SB_BRANCH"
107+ else
108+ echo "$SB_BRANCH was up-to-date"
109+ fi
110+ - name : pullrequest
111+ if : ${{ steps.branch.outputs.existed == 'false' }}
112+ run : gh pr create --base "$GITHUB_REF_NAME" --head "$SB_BRANCH" --fill
0 commit comments