Skip to content

Commit 355b958

Browse files
committed
Harden SimpleAPI GitHub workflows
1 parent 3e5ddc2 commit 355b958

2 files changed

Lines changed: 95 additions & 22 deletions

File tree

‎.github/workflows/maven.yml‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ on:
1010
branches: [ "main" ]
1111

1212
permissions:
13-
contents: write # required for dependency submission
13+
contents: read
1414

1515
jobs:
1616
build:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2020

2121
- name: Set up JDK 21
22-
uses: actions/setup-java@v4
22+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
2323
with:
2424
java-version: '21'
2525
distribution: 'temurin'
@@ -28,10 +28,18 @@ jobs:
2828
- name: Build with Maven
2929
run: mvn -B -f SimpleAPI/pom.xml package
3030

31-
# Only run dependency graph submission on push (not pull_request)
31+
# Dependency submission needs write access, so keep it out of the build job.
32+
submit-dependency-snapshot:
33+
if: github.event_name == 'push'
34+
runs-on: ubuntu-latest
35+
permissions:
36+
contents: write
37+
steps:
38+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
with:
40+
persist-credentials: false
41+
3242
- name: Submit Dependency Snapshot
33-
if: github.event_name == 'push'
34-
uses: advanced-security/maven-dependency-submission-action@v5
43+
uses: advanced-security/maven-dependency-submission-action@b275d12641ac2d2108b2cbb7598b154ad2f2cee8 # v5.0.0
3544
with:
36-
directory: SimpleAPI # path to pom.xml
37-
# optional: maven-args: "-DskipTests"
45+
directory: SimpleAPI

‎.github/workflows/publish-javadoc.yml‎

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,87 @@ name: Deploy Javadoc
33
on:
44
release:
55
types: [published]
6-
branches:
7-
- master
8-
- main
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: github-pages
12+
cancel-in-progress: false
913

1014
jobs:
11-
publish:
15+
verify-release:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
outputs:
20+
eligible: ${{ steps.eligibility.outputs.eligible }}
21+
commit: ${{ steps.eligibility.outputs.commit }}
22+
steps:
23+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
ref: main
26+
fetch-depth: 0
27+
persist-credentials: false
28+
29+
- name: Verify release tag is on main
30+
id: eligibility
31+
env:
32+
PRERELEASE: ${{ github.event.release.prerelease }}
33+
TAG_NAME: ${{ github.event.release.tag_name }}
34+
run: |
35+
set -euo pipefail
36+
if [[ "$PRERELEASE" == "true" ]]; then
37+
echo "eligible=false" >> "$GITHUB_OUTPUT"
38+
exit 0
39+
fi
40+
41+
tag_commit="$(git rev-parse --verify "refs/tags/${TAG_NAME}^{commit}")"
42+
if git merge-base --is-ancestor "$tag_commit" origin/main; then
43+
echo "eligible=true" >> "$GITHUB_OUTPUT"
44+
echo "commit=$tag_commit" >> "$GITHUB_OUTPUT"
45+
else
46+
echo "eligible=false" >> "$GITHUB_OUTPUT"
47+
fi
48+
49+
build:
50+
needs: verify-release
51+
if: needs.verify-release.outputs.eligible == 'true'
1252
runs-on: ubuntu-latest
53+
permissions:
54+
contents: read
1355
steps:
14-
- name: Deploy JavaDoc 🚀
15-
uses: MathieuSoysal/Javadoc-publisher.yml@main
56+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1657
with:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
javadoc-branch: gh-pages
19-
java-version: 21
20-
target-folder: ''
21-
project: maven # or gradle
22-
# subdirectories: moduleA moduleB #for subdirectories support, needs to be run with custom command
23-
custom-command: mvn -f SimpleAPI/pom.xml deploy -P javadoc javadoc:aggregate
24-
javadoc-source-folder: 'SimpleAPI/target/reports/apidocs'
58+
ref: ${{ needs.verify-release.outputs.commit }}
59+
persist-credentials: false
60+
61+
- name: Set up JDK 21
62+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
63+
with:
64+
java-version: '21'
65+
distribution: temurin
66+
cache: maven
67+
68+
- name: Build Javadoc
69+
run: mvn -B -f SimpleAPI/pom.xml clean package -P javadoc javadoc:aggregate
70+
71+
- name: Upload Pages artifact
72+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
73+
with:
74+
path: SimpleAPI/target/reports/apidocs
75+
76+
deploy:
77+
needs: [verify-release, build]
78+
if: needs.verify-release.outputs.eligible == 'true'
79+
runs-on: ubuntu-latest
80+
environment:
81+
name: github-pages
82+
url: ${{ steps.deployment.outputs.page_url }}
83+
permissions:
84+
pages: write
85+
id-token: write
86+
steps:
87+
- name: Deploy to GitHub Pages
88+
id: deployment
89+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

0 commit comments

Comments
 (0)