Skip to content

Commit

Permalink
chore(ci): refactor out set up steps (#10249)
Browse files Browse the repository at this point in the history
Want to keep working on CI every now and then. Starting by cleaning up
some things so it's easier to reason about. Most jobs run the following
steps:

- enable corepack (this should go away one day when the setup node
action supports it)
- set up node
- enable corepack again (for windows)
- set up yarn cache
- yarn install
- build

Refactoring these out into a composite action so that we can save some
lines in ci.yml which is starting to get quite long. I can also document
some things better this way.
  • Loading branch information
jtoar committed Mar 17, 2024
1 parent 93459f9 commit 9283e2b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 311 deletions.
61 changes: 61 additions & 0 deletions .github/actions/set-up-job/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Set up job
description: >
Everything you need to run a job in CI.
Checkout this repo (redwoodjs/redwood), set up Node.js, yarn install, and build.
inputs:
set-up-yarn-cache:
description: >
For some actions, setting up the yarn cache takes longer than it would to just yarn install.
required: false
default: true

yarn-install-directory:
description: >
The directory to run `yarn install` in.
required: false

build:
description: >
Whether or not to run `yarn build` to build all the framework packages.
required: false
default: true

runs:
using: composite

steps:
- name: ⬢ Enable Corepack
shell: bash
run: corepack enable

- name: ⬢ Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

# We have to enable Corepack again for Windows. 🤷
# In general, we're waiting on [this issue](https://github.com/actions/setup-node/issues/531)
# to be resolved so that `actions/setup-node@v4` has first-class Corepack support.
- name: ⬢ Enable Corepack
if: runner.os == 'Windows'
shell: bash
run: corepack enable

- name: 🐈 Set up yarn cache
if: inputs.set-up-yarn-cache == 'true'
uses: ./.github/actions/set-up-yarn-cache

# One of our dependencies is on GitHub instead of NPM and without authentication
# we'll get rate limited and this step becomes flaky.
- name: 🐈 Yarn install
shell: bash
working-directory: ${{ inputs.yarn-install-directory }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: yarn install --inline-builds

- name: 🏗️ Build
if: inputs.build == 'true'
shell: bash
run: yarn build
14 changes: 5 additions & 9 deletions .github/workflows/check-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- uses: actions/setup-node@v4
- name: Set up job
uses: ./.github/actions/set-up-job
with:
node-version: 20

- run: yarn install
working-directory: ./.github/actions/check_changesets
set-up-yarn-cache: false
yarn-install-directory: ./.github/actions/check_changesets
build: false

- name: Check changesets
uses: ./.github/actions/check_changesets
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/check-create-redwood-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- uses: actions/setup-node@v4
- name: Set up job
uses: ./.github/actions/set-up-job
with:
node-version: 20

- run: yarn install
working-directory: ./.github/actions/check_create_redwood_app
set-up-yarn-cache: false
yarn-install-directory: ./.github/actions/check_create_redwood_app
build: false

- name: Check create redwood app
uses: ./.github/actions/check_create_redwood_app
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/check-test-project-fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- name: ⬢ Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: 🐈 Set up yarn cache
if: "!contains(github.event.pull_request.labels.*.name, 'fixture-ok')"
uses: ./.github/actions/set-up-yarn-cache

- name: 🐈 Yarn install
if: "!contains(github.event.pull_request.labels.*.name, 'fixture-ok')"
run: yarn install --inline-builds
env:
GITHUB_TOKEN: ${{ github.token }}

- name: 🔨 Build
- name: Set up job
if: "!contains(github.event.pull_request.labels.*.name, 'fixture-ok')"
run: yarn build
uses: ./.github/actions/set-up-job

- name: Rebuild test-project fixture
if: "!contains(github.event.pull_request.labels.*.name, 'fixture-ok')"
Expand Down
Loading

0 comments on commit 9283e2b

Please sign in to comment.