The documentation for this common use case is sorely lacking...
Why this was needed:
- I had a bunch of CI jobs (lint, test, type checking) that I wanted to run as separate jobs but share the same common steps for running checkout & dependency install
ie: my-github-user/my-repo
with main
as the default branch
.github
/workflows
my-workflow.yml
/actions
/yarn-install
action.yml
name: CI
on: push
jobs:
test:
steps:
- uses: my-github-user/my-repo/.github/actions/yarn-install@main
- name: Run Jest
run: yarn test
lint:
steps:
- uses: my-github-user/my-repo/.github/actions/yarn-install@main
- name: Run Lint
run: yarn lint
name: yarn-install
description: cached yarn install with checkout
runs:
using: 'composite'
steps:
- uses: actions/checkout@v2
- name: Get yarn cache path
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
shell: bash
- name: Cache node modules
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install modules
run: yarn
shell: bash
Adding this workflow on a branch before the action.yml file exists on your main branch requires changing the @main
commit ref in the uses
in your workflow job definition to point to the commit you want to test on your branch. When you're ready to merge, change in back to your main branch name (expect CI to fail), and merge.
The documentation makes it seem like you can locally reference an action using the non-repo notation of: ./.github/actions/yarn-install
, but I can say this doesn't work and I tried a few different versions of this.
@gersona thanks for sharing, do you have a link for reference?