Skip to content

Commit 50fba3c

Browse files
committed
feat: update GitHub workflows with permissions and action versions
Signed-off-by: Nora Blomaard <n.blomaard@gmail.com>
1 parent 53a4926 commit 50fba3c

File tree

5 files changed

+83
-81
lines changed

5 files changed

+83
-81
lines changed

.github/workflows/build-project.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
- 'main'
1414
- 'develop'
1515

16+
permissions:
17+
contents: read
18+
1619
jobs:
1720
build:
1821
name: Build
@@ -21,31 +24,31 @@ jobs:
2124

2225
steps:
2326
- name: Checkout
24-
uses: actions/checkout@v6
27+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2528

2629
- name: Cache Docker Register
27-
uses: actions/cache@v5
30+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
2831
with:
2932
path: /tmp/.buildx-cache
3033
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
3134
- name: Cache Maven packages
32-
uses: actions/cache@v5
35+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
3336
with:
3437
path: ~/.m2
3538
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
3639
restore-keys: ${{ runner.os }}-m2
3740

3841
- name: Set up Docker Buildx
3942
id: buildx
40-
uses: docker/setup-buildx-action@v3
43+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
4144
- name: Set up JDK 17
42-
uses: actions/setup-java@v5
45+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
4346
with:
4447
distribution: 'zulu'
4548
java-version: '17'
4649

4750
- name: Create custom Maven Settings.xml
48-
uses: whelk-io/maven-settings-xml-action@v22
51+
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
4952
with:
5053
output_file: custom_maven_settings.xml
5154
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'

.github/workflows/release-please.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,48 @@ jobs:
1717
release_please:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: googleapis/release-please-action@v4
20+
- uses: googleapis/release-please-action@c3fc4de07084f75a2b61a5b933069bda6edf3d5c # v4
2121
id: release
2222
with:
2323
target-branch: main
2424
- name: Checkout
2525
if: ${{ steps.release.outputs.release_created }}
26-
uses: actions/checkout@v6
26+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2727

2828
- name: Cache Docker Register
2929
if: ${{ steps.release.outputs.release_created }}
30-
uses: actions/cache@v5
30+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
3131
with:
3232
path: /tmp/.buildx-cache
3333
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
3434
- name: Cache Maven packages
3535
if: ${{ steps.release.outputs.release_created }}
36-
uses: actions/cache@v5
36+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
3737
with:
3838
path: ~/.m2
3939
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
4040
restore-keys: ${{ runner.os }}-m2
4141

4242
- name: Set up JDK 17
4343
if: ${{ steps.release.outputs.release_created }}
44-
uses: actions/setup-java@v5
44+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
4545
with:
4646
distribution: 'zulu'
4747
java-version: '17'
4848
- name: Set up Docker Buildx
4949
if: ${{ steps.release.outputs.release_created }}
5050
id: buildx
51-
uses: docker/setup-buildx-action@v3
51+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
5252
- name: Login to Docker Hub
5353
if: ${{ steps.release.outputs.release_created }}
54-
uses: docker/login-action@v3
54+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
5555
with:
5656
username: ${{ secrets.DOCKER_HUB_USERNAME }}
5757
password: ${{ secrets.DOCKER_HUB_TOKEN }}
5858

5959
- name: Create custom Maven Settings.xml
6060
if: ${{ steps.release.outputs.release_created }}
61-
uses: whelk-io/maven-settings-xml-action@v22
61+
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
6262
with:
6363
output_file: custom_maven_settings.xml
6464
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'

.github/workflows/reuse.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ name: REUSE Compliance Check
66

77
on: push
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
test:
1114
runs-on: ubuntu-latest
1215
steps:
1316
- name: Checkout
14-
uses: actions/checkout@v6
17+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
1518
- name: REUSE Compliance Check
16-
uses: fsfe/reuse-action@v6
19+
uses: fsfe/reuse-action@676e2d560c9a403aa252096d99fcab3e1132b0f5 # v6
1720

.github/workflows/sonarcloud-analysis.yml

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,96 +14,98 @@ jobs:
1414
runs-on: ubuntu-latest
1515
if: github.event.workflow_run.conclusion == 'success'
1616
timeout-minutes: 15
17+
permissions:
18+
contents: read
19+
actions: read
20+
pull-requests: read
1721
steps:
1822
- name: echo event
1923
run: cat $GITHUB_EVENT_PATH
2024
- name: Download PR number artifact
21-
if: github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
22-
uses: dawidd6/action-download-artifact@v14
25+
if: github.event.workflow_run.event == 'pull_request'
26+
uses: dawidd6/action-download-artifact@5c98f0b039f36ef966fdb7dfa9779262785ecb05 # v14
2327
with:
2428
workflow: SonarCloud Build
2529
run_id: ${{ github.event.workflow_run.id }}
2630
name: PR_NUMBER
2731
- name: Read PR_NUMBER.txt
28-
if: github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
32+
if: github.event.workflow_run.event == 'pull_request'
2933
id: pr_number
30-
uses: juliangruber/read-file-action@v1
34+
uses: juliangruber/read-file-action@b549046febe0fe86f8cb4f93c24e284433f9ab58 # v1
3135
with:
3236
path: ./PR_NUMBER.txt
3337
- name: Request GitHub API for PR data
34-
if: github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
35-
uses: octokit/request-action@v2.x
38+
if: github.event.workflow_run.event == 'pull_request'
39+
uses: octokit/request-action@05a2312de9f8207044c4c9e41fe19703986acc13 # v2.x
3640
id: get_pr_data
3741
with:
3842
route: GET /repos/{full_name}/pulls/{number}
3943
number: ${{ steps.pr_number.outputs.content }}
4044
full_name: ${{ github.event.repository.full_name }}
4145
env:
4246
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43-
- uses: actions/checkout@v6
47+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
4448
with:
45-
repository: ${{ github.event.workflow_run.head_repository.full_name }}
46-
ref: ${{ github.event.workflow_run.head_branch }}
4749
fetch-depth: 0
48-
- name: Checkout base branch
49-
if: github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target')
50-
run: |
51-
git remote add upstream ${{ github.event.repository.clone_url }}
52-
git fetch upstream
53-
git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
54-
git checkout ${{ github.event.workflow_run.head_branch }}
55-
git clean -ffdx && git reset --hard HEAD
50+
- name: Download build artifacts
51+
uses: dawidd6/action-download-artifact@5c98f0b039f36ef966fdb7dfa9779262785ecb05 # v14
52+
with:
53+
workflow: SonarCloud Build
54+
run_id: ${{ github.event.workflow_run.id }}
55+
name: build-artifacts
5656
- name: Cache SonarCloud packages
57-
uses: actions/cache@v5
57+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
5858
with:
5959
path: ~/.sonar/cache
6060
key: ${{ runner.os }}-sonar
6161
restore-keys: ${{ runner.os }}-sonar
62-
- name: Cache Maven packages
63-
uses: actions/cache@v5
64-
with:
65-
path: ~/.m2
66-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
67-
restore-keys: ${{ runner.os }}-m2
6862

6963
- name: Set up JDK 17
70-
uses: actions/setup-java@v5
64+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
7165
with:
7266
distribution: 'zulu'
7367
java-version: '17'
68+
cache: 'maven'
7469

7570
- name: Set Common Sonar Variables
7671
id: sonar_env
72+
# Use $GITHUB_OUTPUT; the legacy ##[set-output] syntax is deprecated and disabled.
7773
run: |
78-
echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
79-
-Dsonar.projectKey=com-pas_compas-scl-auto-alignment \
80-
-Dsonar.organization=com-pas )"
74+
echo "sonar_opts=-Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=com-pas_compas-scl-auto-alignment -Dsonar.organization=com-pas" >> "$GITHUB_OUTPUT"
8175
- name: Create custom Maven Settings.xml
82-
uses: whelk-io/maven-settings-xml-action@v22
76+
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
8377
with:
8478
output_file: custom_maven_settings.xml
8579
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
8680
- name: Build and analyze (Pull Request)
87-
if: ${{ github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target') }}
81+
if: ${{ github.event.workflow_run.event == 'pull_request' }}
82+
# Pass user-controlled PR metadata through env vars to prevent shell/argument injection.
8883
env:
8984
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9085
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
86+
SONAR_PR_BRANCH: ${{ fromJson(steps.get_pr_data.outputs.data).head.ref }}
87+
SONAR_PR_KEY: ${{ fromJson(steps.get_pr_data.outputs.data).number }}
88+
SONAR_PR_BASE: ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
89+
SONAR_SCM_REVISION: ${{ github.event.workflow_run.head_sha }}
9190
run: |
9291
./mvnw -B -s custom_maven_settings.xml -Psonar \
9392
${{ steps.sonar_env.outputs.sonar_opts }} \
94-
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \
95-
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \
96-
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \
97-
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
98-
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
93+
"-Dsonar.pullrequest.branch=$SONAR_PR_BRANCH" \
94+
"-Dsonar.pullrequest.key=$SONAR_PR_KEY" \
95+
"-Dsonar.pullrequest.base=$SONAR_PR_BASE" \
96+
"-Dsonar.scm.revision=$SONAR_SCM_REVISION" \
97+
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
9998
- name: Build and analyze (Push)
10099
if: ${{ github.event.workflow_run.event == 'push' }}
100+
# Pass user-controlled branch/revision values through env vars to prevent injection.
101101
env:
102102
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103103
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
104+
SONAR_SCM_REVISION: ${{ github.event.workflow_run.head_sha }}
105+
SONAR_BRANCH_NAME: ${{ github.event.workflow_run.head_branch }}
104106
run: |
105107
./mvnw -B -s custom_maven_settings.xml -Psonar \
106108
${{ steps.sonar_env.outputs.sonar_opts }} \
107-
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
108-
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} \
109-
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
109+
"-Dsonar.scm.revision=$SONAR_SCM_REVISION" \
110+
"-Dsonar.branch.name=$SONAR_BRANCH_NAME" \
111+
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

.github/workflows/sonarcloud-build.yml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,60 @@ on:
1212
branches:
1313
- 'main'
1414
- 'develop'
15-
pull_request_target:
16-
branches:
17-
- 'main'
18-
- 'develop'
1915

2016
jobs:
2117
precheck-build:
2218
name: Pre Check Build
2319
runs-on: ubuntu-latest
2420
timeout-minutes: 30
25-
26-
if: ${{ (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
21+
permissions:
22+
contents: read
2723
steps:
2824
- name: Checkout
29-
uses: actions/checkout@v6
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
3026
with:
3127
fetch-depth: 0
3228

3329
- name: Cache SonarCloud packages
34-
uses: actions/cache@v5
30+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
3531
with:
3632
path: ~/.sonar/cache
3733
key: ${{ runner.os }}-sonar
3834
restore-keys: ${{ runner.os }}-sonar
39-
- name: Cache Maven packages
40-
uses: actions/cache@v5
41-
with:
42-
path: ~/.m2
43-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
44-
restore-keys: ${{ runner.os }}-m2
4535

4636
- name: Set up JDK 17
47-
uses: actions/setup-java@v5
37+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
4838
with:
4939
distribution: 'zulu'
5040
java-version: '17'
41+
cache: 'maven'
5142

5243
- name: Create custom Maven Settings.xml
53-
uses: whelk-io/maven-settings-xml-action@v22
44+
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
5445
with:
5546
output_file: custom_maven_settings.xml
5647
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
57-
- name: Build and analyze (Pull Request)
58-
if: ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
59-
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
run: |
62-
./mvnw -B -s custom_maven_settings.xml clean verify
63-
- name: Build and analyze (Push)
64-
if: ${{ github.event_name == 'push' }}
48+
- name: Build
6549
env:
6650
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6751
run: |
6852
./mvnw -B -s custom_maven_settings.xml clean verify
53+
- name: Upload build artifacts
54+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
55+
with:
56+
name: build-artifacts
57+
path: |
58+
service/src/
59+
app/src/
60+
service/target/
61+
app/target/
62+
retention-days: 1
6963
- name: Save PR number to file
70-
if: ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
64+
if: ${{ github.event_name == 'pull_request' }}
7165
run: echo ${{ github.event.pull_request.number }} > PR_NUMBER.txt
7266
- name: Archive PR number
73-
if: ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
74-
uses: actions/upload-artifact@v6
67+
if: ${{ github.event_name == 'pull_request' }}
68+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
7569
with:
7670
name: PR_NUMBER
7771
path: PR_NUMBER.txt

0 commit comments

Comments
 (0)