Skip to content

Commit

Permalink
Merge pull request #2619 from aiidtest/feature-deploy-ignore-cache
Browse files Browse the repository at this point in the history
On demand workflow triggers, allow build caches to be skipped, allow force deploy, allow custom runners from env
  • Loading branch information
kepae authored Feb 12, 2024
2 parents 0077145 + 58fb581 commit 8eed478
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 20 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/cache-modifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Cache Modifier

on:
workflow_call:
inputs:
skip-cache:
description: "Skip Cache"
required: true
default: "false"
type: string
outputs:
cache-modifier:
description: "Cache Modifier"
value: ${{ jobs.prepare-cache.outputs.cache-modifier }}

jobs:
prepare-cache:
runs-on: ubuntu-latest
outputs:
cache-modifier: ${{ steps.set-cache-modifier.outputs.cache-modifier }}
steps:
- name: Set cache modifier
id: set-cache-modifier
run: |
if [[ "${{ inputs.skip-cache }}" == "true" ]]; then
echo "cache-modifier=$(date +%s)" >> $GITHUB_OUTPUT
else
echo "cache-modifier=" >> $GITHUB_OUTPUT
fi
10 changes: 9 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ on:
description: The commit SHA to deploy
type: string
required: true
runner-label:
description: The label of the runner to use
type: string
cache-modifier:
description: A modifier for the cache key used to bypass existing cache
type: string
required: false
default: ""

jobs:
netlify-deploy:
Expand All @@ -43,7 +51,7 @@ jobs:
with:
path: |
site/gatsby-site/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-${{ inputs.cache-modifier }}

- name: Set up Node.js
uses: actions/setup-node@v4
Expand Down
36 changes: 30 additions & 6 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,66 @@ on:
branches:
- master
schedule:
- cron: '0 6,18 * * *'

- cron: "0 6,18 * * *"
workflow_dispatch:
inputs:
skip-cache:
description: "Skip Cache"
required: true
default: true
type: boolean
force-deploy:
description: "Deploy even if tests fail"
required: true
default: false
type: boolean
jobs:

cache-modifier:
uses: ./.github/workflows/cache-modifier.yml
with:
skip-cache: ${{ github.event.inputs.skip-cache }}

call-atlas:
uses: ./.github/workflows/realm.yml
secrets: inherit
needs: cache-modifier
with:
sha: ${{ github.sha }}
environment: production

call-test-build:
uses: ./.github/workflows/test-build.yml
secrets: inherit
needs: call-atlas
needs: [cache-modifier, call-atlas]
with:
sha: ${{ github.sha }}
environment: production
netlify-context: production
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-test:
uses: ./.github/workflows/test.yml
needs: call-test-build
needs: [cache-modifier, call-test-build]
secrets: inherit
with:
sha: ${{ github.sha }}
environment: production
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-deploy:
if: inputs.force-deploy == true || success()
uses: ./.github/workflows/deploy.yml
needs: call-test
needs: [cache-modifier, call-test]
secrets: inherit
permissions:
pull-requests: write
with:
environment: production
sha: ${{ github.sha }}
netlify-context: production
netlify-alias:
netlify-alias:
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}
34 changes: 29 additions & 5 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,65 @@ on:
push:
branches:
- staging
workflow_dispatch:
inputs:
skip-cache:
description: "Skip Cache"
required: true
default: true
type: boolean
force-deploy:
description: "Deploy even if tests fail"
required: true
default: false
type: boolean

jobs:
cache-modifier:
uses: ./.github/workflows/cache-modifier.yml
with:
skip-cache: ${{ github.event.inputs.skip-cache }}

call-atlas:
uses: ./.github/workflows/realm.yml
secrets: inherit
needs: cache-modifier
with:
sha: ${{ github.sha }}
environment: staging

call-test-build:
uses: ./.github/workflows/test-build.yml
secrets: inherit
needs: call-atlas
needs: [cache-modifier, call-atlas]
with:
sha: ${{ github.sha }}
environment: staging
netlify-context: production
runner-label: ${{ vars.STAGING_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-test:
call-test:
uses: ./.github/workflows/test.yml
needs: call-test-build
needs: [cache-modifier, call-test-build]
secrets: inherit
with:
sha: ${{ github.sha }}
environment: staging
runner-label: ${{ vars.STAGING_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-deploy:
if: inputs.force-deploy == true || success()
uses: ./.github/workflows/deploy.yml
needs: call-test
needs: [cache-modifier, call-test]
secrets: inherit
permissions:
pull-requests: write
with:
environment: staging
sha: ${{ github.sha }}
netlify-context: production
netlify-alias:
netlify-alias:
runner-label: ${{ vars.STAGING_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}
12 changes: 10 additions & 2 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ on:
description: The Netlify context use when building
type: string
required: true
runner-label:
description: The label of the runner to use
type: string
cache-modifier:
description: A modifier for the cache key used to bypass existing cache
type: string
required: false
default: ""

jobs:
test:
Expand All @@ -35,7 +43,7 @@ jobs:
path: |
site/gatsby-site/node_modules
~/.cache/Cypress
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-${{ inputs.cache-modifier}}

- name: Install NPM dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -98,4 +106,4 @@ jobs:
path: |
site/gatsby-site/public
site/gatsby-site/.cache/functions
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.sha }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.sha }}-${{ inputs.cache-modifier }}
21 changes: 15 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ on:
workflow_call:
inputs:
environment:
description: 'The Github environment to load secrets from'
description: The Github environment to load secrets from
type: string
required: true
sha:
description: "The commit SHA to run the tests against"
description: The commit SHA to run the tests against
type: string
required: true
runner-label:
description: The label of the runner to use
type: string
cache-modifier:
description: A modifier for the cache key used to bypass existing cache
type: string
required: false
default: ""

jobs:
test:
name: Run Cypress tests
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
runs-on:
labels: ${{ inputs.runner-label || 'ubuntu-latest' }}
defaults:
run:
shell: bash
Expand Down Expand Up @@ -47,7 +56,7 @@ jobs:
path: |
site/gatsby-site/node_modules
~/.cache/Cypress
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-${{ inputs.cache-modifier }}

- name: Install NPM dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
Expand All @@ -65,7 +74,7 @@ jobs:
path: |
site/gatsby-site/public
site/gatsby-site/.cache/functions
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.sha }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.sha }}-${{ inputs.cache-modifier }}

- name: Extract branch name
shell: bash
Expand Down Expand Up @@ -118,4 +127,4 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

0 comments on commit 8eed478

Please sign in to comment.