Skip to main content

GitHub Actions Tips & Tricks

Security

https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository

https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions

Tips & Tricks

Write Complex Steps in github-script

Rather than try some impossible concoction of YAML, use typescript to define your CI/CD logic.

https://github.com/actions/github-script

Easily Write Files in Workflows

The 1arp/create-a-file-action action is convenient for writing files.

    - name: Create ${{ steps.vars.outputs.argocd_app_root }}/config.yaml
uses: 1arp/[email protected]
with:
path: "some/dir"
file: config.yaml
content: |
name: "${{ github.event.deployment.payload.app }}"
manifests: "${{ steps.vars.outputs.argocd_app_manifests }}"
namespace: "${{ inputs.namespace }}"

Checkout and Run Private GitHub Actions

info

GitHub Enterprise users can now use private actions natively within the organization.

https://github.blog/changelog/2022-01-21-share-github-actions-within-your-enterprise/

      - name: Checkout Shared Actions
uses: actions/checkout@v2
with:
repository: acme/actions
path: ./.github/actions
token: ${{ secrets.CROSS_REPO_TOKEN }}

- name: Hello World
uses: ./.github/actions/hello-world
id: hello-world

Use Empty Commits to Trigger Actions

git commit --allow-empty --message 'bump'

Use workflow_dispatch to Manually Trigger Workflows

In this example, the workflow will trigger on workflow_dispatch and prompt the user to enter the required input for delete. Note, delete is just an example; the input parameters can be whatever you want.

on:
# Enable manual runs
workflow_dispatch:
inputs:
delete:
description: 'Set to "true" to actually delete stuff'
required: true
default: 'false'

Known Limitations

There are a lot of non-obvious limitations when working with GitHub Actions. Here are the ones we’ve been bit by in developing workflows. Also, make sure to check out the Public Roadmap for GHA.

Roadmap Items

These are some roadmap items we’re excited to see implemented:

General

https://github.com/github/roadmap/issues/74

Composite Actions

Shared Workflows

References