Fix Output File Names for PR Test Builds (#471)

[COMBINE]
commits = ["fbd1584e7baed4a3603e3c810066603185f1b230"]
[COMBINE]
This commit is contained in:
IntegerLimit 2023-10-21 16:32:25 +11:00 committed by GitHub
parent b15494c8bf
commit d9909efcbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -8,7 +8,12 @@ export default async function transformManifestVersion(): Promise<void> {
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];

View File

@ -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);