Skip to content

Instantly share code, notes, and snippets.

@romain-grecourt
Last active August 1, 2023 16:28
Show Gist options
  • Save romain-grecourt/de6a6e5ecbdd8c2da62922a02ef1d6d6 to your computer and use it in GitHub Desktop.
Save romain-grecourt/de6a6e5ecbdd8c2da62922a02ef1d6d6 to your computer and use it in GitHub Desktop.
GitHub action cheat sheet

Links

Local custom actions

uses: ./.github/actions/my-action

Unique workflow id

github.run_id does not change when the workflow is re-run, however we can combine it with github.run_attempt to get a unique id.

${{ github.run_id }}-${{ github.run_attempt }}

Delete workflow runs

REPO="romain-grecourt/helidon-build-tools"
for id in `gh run list --json databaseId  -q '.[].databaseId' -L 500 -R "${REPO}" | tail -150` ; do
  echo $id ; gh api "repos/${REPO}/actions/runs/${id}" -X DELETE > /dev/null
done

Customizing Matrix Job Name

Some context are only available at certain times. See https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability

Here are the context that can be used for a job name: github, needs, strategy, matrix, vars, inputs

  cli:
    needs: build
    timeout-minutes: 15
    strategy:
      matrix:
        os: [ ubuntu-20.04, windows-2022, macos-12 ]
        include:
          - os: ubuntu-20.04
            platform: linux-amd64
          - os: windows-2022
            platform: windows-amd64
          - os: macos-12
            platform: darwin-amd64
    runs-on: ${{ matrix.os }}
    name: cli/${{ matrix.platform }}

Conditional environment variable

env:
  MAVEN_ARGS: |
    ${{ env.MAVEN_ARGS }}
    -Dcache.createArchive=${{ inputs.build-cache == 'read-write' && 'true' || 'false' }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment