Repository navigation
ci: pin third-party actions to SHAs and gate PRs on an in-repo build #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # PR 建置門檻: 讓 auto-merge 的 PR (如 bump-spring 開的相依升版 PR) 在合併前 | ||
| # 有一個 in-repo 的建置/測試狀態可被 branch protection 要求, 不必只依賴 repo 外的 Jenkins。 | ||
| # 註: 完整的 java/spring 交叉測試仍由 Jenkinsfile 的 Matrix Tests 負責, 這裡只跑 pom.xml 當前組合。 | ||
| name: Build | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [jakarta] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| cache: 'maven' | ||
| - run: make test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ jobs: | |
| - id: get-current-version | ||
| run: echo "current_version=$(make version)" >> "$GITHUB_OUTPUT" | ||
| - id: bump | ||
| uses: "WyriHaximus/github-action-next-semvers@v1" | ||
| uses: WyriHaximus/github-action-next-semvers@d079934efaf011a4cf8912d4637097fe35d32b93 # v1 | ||
| with: | ||
| version: ${{ steps.get-current-version.outputs.current_version }} | ||
| outputs: | ||
|
|
@@ -58,7 +58,7 @@ jobs: | |
| exit 1; | ||
| fi | ||
| - id: check-version | ||
| uses: mukunku/[email protected] | ||
| uses: mukunku/tag-exists-action@5c39604fe8aef7e65acb6fbcf96ec580f7680313 # v1.7.0 | ||
| with: | ||
| tag: '${{ steps.determine-version.outputs.final_version }}' | ||
| - id: fail-if-version-exists | ||
|
|
@@ -73,7 +73,7 @@ jobs: | |
| needs: ensure-version-not-exists | ||
| steps: | ||
| - id: specification-mapper-bump-snapshot | ||
| uses: shihyuho/go-jenkins-trigger@v2 | ||
| uses: shihyuho/go-jenkins-trigger@d6f3216fa650324688da24cbf081472e29d35d57 # v2 | ||
| with: | ||
| jenkins-url: "${{ secrets.JENKINS_URL }}" | ||
| jenkins-user: "${{ secrets.JENKINS_USER }}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ jobs: | |
| with: | ||
| client-id: ${{ vars.CI_APP_CLIENT_ID }} | ||
| private-key: ${{ secrets.CI_APP_PRIVATE_KEY }} | ||
| - uses: googleapis/[email protected] | ||
| - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 | ||
| id: rp | ||
| with: | ||
| token: ${{ steps.app-token.outputs.token }} | ||
|
|
@@ -43,7 +43,7 @@ jobs: | |
| if: needs.release-please.outputs.release_created == 'true' | ||
| steps: | ||
| - id: specification-mapper-release | ||
| uses: shihyuho/go-jenkins-trigger@v2 | ||
| uses: shihyuho/go-jenkins-trigger@d6f3216fa650324688da24cbf081472e29d35d57 # v2 | ||
| with: | ||
| jenkins-url: "${{ secrets.JENKINS_URL }}" | ||
| jenkins-user: "${{ secrets.JENKINS_USER }}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,7 +154,10 @@ spec: | |
| } | ||
| failure { | ||
| script { | ||
| if (env.BRANCH_NAME == 'main' | ||
| // BRANCH_IS_PRIMARY 由 multibranch 的 branch-api 在 SCM 預設分支上設為 'true', | ||
| // 不必隨預設分支改名而改這裡; 非 multibranch job 不會有這個變數, 故 fallback 比對分支名 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit · Readability 「非 multibranch job 不會有這個變數, 故 fallback 比對分支名」——但 fallback 真正有價值的情境是另一個:multibranch job 但 branch-api 版本較舊、或 SCM source 非 GitHub,導致 primary-branch metadata 取不到而 程式行為正確,只有註解寫的理由不成立(PR 描述裡也有同樣的說法)。 |
||
| def isPrimaryBranch = env.BRANCH_IS_PRIMARY == 'true' || env.BRANCH_NAME == 'jakarta' | ||
| if (isPrimaryBranch | ||
| // 若短時間太密集的 push, 之前的 job 會被 jenkins 中斷,這樣就可能會就連第一步都還沒執行的狀況,但也算是失敗 | ||
| // 然而取得 git 資訊就在第一步,所以至少要第一步都有執行完才發佈 slack 吧 | ||
| && env.LAST_COMMIT_AUTHOR_NAME && env.LAST_COMMIT_AUTHOR_EMAIL && env.LAST_COMMIT_TIME) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI · Correctness
這個 branch filter 寫死
jakarta,日後預設分支再改名一次,gate 會靜默停止對 PR 執行,而不是大聲失敗——正是這個 PR 在 Jenkinsfile 修掉的同一類死守衛(env.BRANCH_NAME == 'main'在 main 改名成 jakarta 後就永遠為 false)。不算缺陷:
site-build.yml目前也是三處寫死jakarta,這個寫法與既有慣例一致。若想讓它免疫改名,直接省略branches:讓所有 PR 都跑即可。