From d9909efcbf1e1a9f479638945da4102c200dbe1a Mon Sep 17 00:00:00 2001 From: IntegerLimit <103940576+IntegerLimit@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:32:25 +1100 Subject: [PATCH] Fix Output File Names for PR Test Builds (#471) [COMBINE] commits = ["fbd1584e7baed4a3603e3c810066603185f1b230"] [COMBINE] --- .github/workflows/buildpack.yml | 8 ++++++++ .github/workflows/forkprbuildpack.yml | 3 +++ .github/workflows/testbuildpack.yml | 2 ++ tools/tasks/shared/transformVersion.ts | 7 ++++++- tools/util/util.ts | 7 ++++++- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/buildpack.yml b/.github/workflows/buildpack.yml index df7b6b9..d0338e4 100644 --- a/.github/workflows/buildpack.yml +++ b/.github/workflows/buildpack.yml @@ -70,6 +70,12 @@ on: required: false default: false type: boolean + head_ref: + type: string + required: false + true_sha: + type: string + required: false jobs: build: @@ -78,6 +84,8 @@ jobs: env: GITHUB_TAG: ${{ inputs.tag }} RELEASE_TYPE: ${{ inputs.release_type }} + GITHUB_HEAD_REF: ${{ inputs.head_ref }} + TRUE_SHA: ${{ inputs.true_sha }} steps: - name: Checkout Ref diff --git a/.github/workflows/forkprbuildpack.yml b/.github/workflows/forkprbuildpack.yml index ea773ee..4c1a9a9 100644 --- a/.github/workflows/forkprbuildpack.yml +++ b/.github/workflows/forkprbuildpack.yml @@ -22,6 +22,9 @@ jobs: name: Fork PR Build Pack runs-on: ubuntu-latest environment: fork-pr-build-pack + env: + GITHUB_HEAD_REF: ${{ github.head_ref }} + TRUE_SHA: ${{ github.event.pull_request.head.sha }} steps: - name: Checkout Ref uses: actions/checkout@v4 diff --git a/.github/workflows/testbuildpack.yml b/.github/workflows/testbuildpack.yml index 8dbffbc..0974efe 100644 --- a/.github/workflows/testbuildpack.yml +++ b/.github/workflows/testbuildpack.yml @@ -21,5 +21,7 @@ jobs: uses: ./.github/workflows/buildpack.yml with: separate_upload: true + head_ref: ${{ github.head_ref }} + true_sha: ${{ github.event.pull_request.head.sha }} secrets: inherit diff --git a/tools/tasks/shared/transformVersion.ts b/tools/tasks/shared/transformVersion.ts index 4b03517..f95521c 100644 --- a/tools/tasks/shared/transformVersion.ts +++ b/tools/tasks/shared/transformVersion.ts @@ -8,7 +8,12 @@ export default async function transformManifestVersion(): Promise { if (process.env.GITHUB_TAG) { modpackManifest.version = process.env.GITHUB_TAG.replace(/^v/, ""); } - // If SHA is provided and the build isn't tagged, append both the branch and short SHA. + // If Pull Request Branch Name is provided and a 'True SHA' is provided + else if (process.env.GITHUB_HEAD_REF && process.env.TRUE_SHA) { + const shortCommit = process.env.TRUE_SHA.substring(0, 7); + modpackManifest.version = `${process.env.GITHUB_HEAD_REF}-${shortCommit}`; + } + // If SHA and ref is provided, append both the branch and short SHA. else if (process.env.GITHUB_SHA && process.env.GITHUB_REF && process.env.GITHUB_REF.startsWith("refs/heads/")) { const shortCommit = process.env.GITHUB_SHA.substring(0, 7); const branch = /refs\/heads\/(.+)/.exec(process.env.GITHUB_REF)?.[1]; diff --git a/tools/util/util.ts b/tools/util/util.ts index 914545d..0a80b46 100644 --- a/tools/util/util.ts +++ b/tools/util/util.ts @@ -189,7 +189,12 @@ export function makeArtifactNameBody(baseName: string): string { if (process.env.GITHUB_TAG) { return `${baseName}-${process.env.GITHUB_TAG}`; } - // If SHA is provided and the build isn't tagged, append both the branch and short SHA. + // If Pull Request Branch Name is provided and a 'True SHA' is provided + else if (process.env.GITHUB_HEAD_REF && process.env.TRUE_SHA) { + const shortCommit = process.env.TRUE_SHA.substring(0, 7); + return `${baseName}-${process.env.GITHUB_HEAD_REF}-${shortCommit}`; + } + // If SHA and ref is provided, append both the branch and short SHA. else if (process.env.GITHUB_SHA && process.env.GITHUB_REF && process.env.GITHUB_REF.startsWith("refs/heads/")) { const shortCommit = process.env.GITHUB_SHA.substring(0, 7); const branch = /refs\/heads\/(.+)/.exec(process.env.GITHUB_REF);