From 8191dcd0cdbd94650ada2a5cbfef90939964d4f5 Mon Sep 17 00:00:00 2001 From: harrydowning Date: Tue, 15 Oct 2024 21:26:36 +0100 Subject: [PATCH 1/5] feat: add runs-on input param --- .github/workflows/node-pipeline.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/node-pipeline.yml b/.github/workflows/node-pipeline.yml index ded1b49..44d1cd3 100644 --- a/.github/workflows/node-pipeline.yml +++ b/.github/workflows/node-pipeline.yml @@ -14,6 +14,11 @@ on: repository-owner: type: string required: true + runs-on: + type: string + required: false + default: ubuntu-latest + # Scripts check-run: type: string required: false @@ -29,7 +34,7 @@ on: jobs: check: - runs-on: ubuntu-latest + runs-on: ${{ inputs.runs-on }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -38,7 +43,7 @@ jobs: registry-url: ${{ inputs.registry-url }} - run: ${{ inputs.check-run }} release-check: - runs-on: ubuntu-latest + runs-on: ${{ inputs.runs-on }} needs: check if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.repository_owner == ${{ inputs.repository-owner }} steps: @@ -49,7 +54,7 @@ jobs: registry-url: ${{ inputs.registry-url }} - run: ${{ inputs.release-check-run }} release: - runs-on: ubuntu-latest + runs-on: ${{ inputs.runs-on }} needs: release-check if: contains(github.event.head_commit.message, '[release]') && !contains(github.event.head_commit.message, '[pre-release]') env: @@ -64,7 +69,7 @@ jobs: registry-url: ${{ inputs.registry-url }} - run: ${{ inputs.release-run }} pre-release: - runs-on: ubuntu-latest + runs-on: ${{ inputs.runs-on }} needs: release-check if: contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.head_commit.message, '[release]') env: From 1e27f59c05a945ed4a8abd5bf3ef591ecf051efa Mon Sep 17 00:00:00 2001 From: harrydowning Date: Tue, 15 Oct 2024 21:35:45 +0100 Subject: [PATCH 2/5] feat: build stage --- .github/workflows/node-pipeline.yml | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node-pipeline.yml b/.github/workflows/node-pipeline.yml index 44d1cd3..ec52880 100644 --- a/.github/workflows/node-pipeline.yml +++ b/.github/workflows/node-pipeline.yml @@ -3,6 +3,7 @@ name: node-pipeline on: workflow_call: inputs: + # General node-version: type: string required: false @@ -25,12 +26,19 @@ on: release-check-run: type: string required: false + build-run: + type: string + required: false release-run: type: string required: false pre-release-run: type: string required: false + # Artifacts + build-path: + type: string + required: false jobs: check: @@ -53,9 +61,23 @@ jobs: node-version: ${{ inputs.node-version }} registry-url: ${{ inputs.registry-url }} - run: ${{ inputs.release-check-run }} - release: + build: runs-on: ${{ inputs.runs-on }} needs: release-check + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + registry-url: ${{ inputs.registry-url }} + - run: ${{ inputs.build-run }} + - uses: actions/upload-artifact@v4 + with: + name: build-artifact + path: ${{ inputs.build-path }} + release: + runs-on: ${{ inputs.runs-on }} + needs: build if: contains(github.event.head_commit.message, '[release]') && !contains(github.event.head_commit.message, '[pre-release]') env: GH_TOKEN: ${{ github.token }} @@ -67,10 +89,14 @@ jobs: with: node-version: ${{ inputs.node-version }} registry-url: ${{ inputs.registry-url }} + - uses: actions/download-artifact@v4 + with: + name: build-artifact + path: ${{ inputs.build-path }} - run: ${{ inputs.release-run }} pre-release: runs-on: ${{ inputs.runs-on }} - needs: release-check + needs: build if: contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.head_commit.message, '[release]') env: GH_TOKEN: ${{ github.token }} @@ -82,4 +108,8 @@ jobs: with: node-version: ${{ inputs.node-version }} registry-url: ${{ inputs.registry-url }} + - uses: actions/download-artifact@v4 + with: + name: build-artifact + path: ${{ inputs.build-path }} - run: ${{ inputs.pre-release-run }} From 4efad78707ef0b636bbbc4a1511a03d57692df6a Mon Sep 17 00:00:00 2001 From: harrydowning Date: Tue, 15 Oct 2024 21:46:22 +0100 Subject: [PATCH 3/5] fix: ensure unique build artifacts --- .github/workflows/node-pipeline.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node-pipeline.yml b/.github/workflows/node-pipeline.yml index ec52880..4be8af8 100644 --- a/.github/workflows/node-pipeline.yml +++ b/.github/workflows/node-pipeline.yml @@ -73,7 +73,7 @@ jobs: - run: ${{ inputs.build-run }} - uses: actions/upload-artifact@v4 with: - name: build-artifact + name: build-artifact-${{ github.sha }} path: ${{ inputs.build-path }} release: runs-on: ${{ inputs.runs-on }} @@ -91,7 +91,7 @@ jobs: registry-url: ${{ inputs.registry-url }} - uses: actions/download-artifact@v4 with: - name: build-artifact + name: build-artifact-${{ github.sha }} path: ${{ inputs.build-path }} - run: ${{ inputs.release-run }} pre-release: @@ -110,6 +110,6 @@ jobs: registry-url: ${{ inputs.registry-url }} - uses: actions/download-artifact@v4 with: - name: build-artifact + name: build-artifact-${{ github.sha }} path: ${{ inputs.build-path }} - run: ${{ inputs.pre-release-run }} From e1e90af2e6e7c43c94dd2ca242701fe0c5cae6f4 Mon Sep 17 00:00:00 2001 From: harrydowning Date: Tue, 15 Oct 2024 22:05:14 +0100 Subject: [PATCH 4/5] only run build job if build-path defined --- .github/workflows/node-pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/node-pipeline.yml b/.github/workflows/node-pipeline.yml index 4be8af8..05cddc9 100644 --- a/.github/workflows/node-pipeline.yml +++ b/.github/workflows/node-pipeline.yml @@ -64,6 +64,7 @@ jobs: build: runs-on: ${{ inputs.runs-on }} needs: release-check + if: ${{ inputs.build-path }} != '' steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 From 9a873603d02055ee6f536ef4816d0f1c48960911 Mon Sep 17 00:00:00 2001 From: harrydowning Date: Tue, 15 Oct 2024 22:28:53 +0100 Subject: [PATCH 5/5] release if build skipped or success --- .github/workflows/node-pipeline.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node-pipeline.yml b/.github/workflows/node-pipeline.yml index 05cddc9..a8134be 100644 --- a/.github/workflows/node-pipeline.yml +++ b/.github/workflows/node-pipeline.yml @@ -76,9 +76,14 @@ jobs: with: name: build-artifact-${{ github.sha }} path: ${{ inputs.build-path }} - release: + build-check: runs-on: ${{ inputs.runs-on }} needs: build + if: always() && (needs.build.result == 'skipped' || needs.build.result == 'success') + steps: [] # TODO: does this work + release: + runs-on: ${{ inputs.runs-on }} + needs: build-check if: contains(github.event.head_commit.message, '[release]') && !contains(github.event.head_commit.message, '[pre-release]') env: GH_TOKEN: ${{ github.token }} @@ -97,7 +102,7 @@ jobs: - run: ${{ inputs.release-run }} pre-release: runs-on: ${{ inputs.runs-on }} - needs: build + needs: build-check if: contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.head_commit.message, '[release]') env: GH_TOKEN: ${{ github.token }}