GitHub Actions by Example: Actions

Actions reduce workflow steps by providing reusable “code” for common tasks. To run an action, you include the uses keyword pointing to a GitHub repo with the pattern {owner}/{repo}@{ref} or {owner}/{repo}/{path}@{ref} if it’s in a subdirectory. A ref can be a branch, tag, or SHA.

GitHub officially supports many common actions. See the full list here

name: actions-example
    runs-on: ubuntu-latest

The checkout action checks out your repo into the working directory at the ref which triggered the workflow (e.g. a branch that was pushed).

      - uses: actions/checkout@v2

The setup-node action makes node and npm available in the following steps.

      - uses: actions/setup-node@v1

Some actions also have required or optional arguments.

          node-version: '15.8.0'
        name: Install repo dependencies
        run: npm install
        name: Run script from repo
        run: node helloWorld.js

Next example: Environment Variables