Skip to content

Github actions using custom actions


Runners

There actrc file locate at ~/.config/act/actrc for set the default runner in the file

-P ubuntu-latest=ubuntu:22.04
-P ubuntu-22.04=node:16-bullseye-slim

Composite actions

Simple demo

Using act to run the demo locally:

1
2
3
4
5
6
7
.github
    ├── actions
       └── my_action
           └── action.yaml
    └── workflows
        ├── demo.yml
        └── README.md
workflows/demo.yml
name: demos
on: [workflow_dispatch]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: hello world
        run: echo "Hello from act!"
      - name: run my action
        uses: ./.github/actions/my_action
actions/my_action/action.yaml
1
2
3
4
5
6
7
8
name: "my Action"
description: "My Action"
runs:
  using: "composite"
  steps:
    - name: hello composite
      run: echo "Hello from my composite act!"
      shell: bash

usage

act -j test --bind --directory . --pull=false

bind directory

Using --bind --directory . to bind local directory to the container, it's need to find actions folder


Composite with args

1
2
3
4
5
6
.github
    ├── actions
       └── action_with_args
           └── action.yaml
    └── workflows
        └── demo.yml
workflows/demo.yml
name: demos
on: [workflow_dispatch]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: hello world
        run: echo "Hello from act!"
      - name: run my action
        uses: ./.github/actions/action_with_args
        with:
          arg1: "value 1"
actions/action_with_args/action.yaml
name: "my Action with args"
description: "My Action"
inputs:
  arg1:
    description: "arg1"
    required: true
  arg2:
    description: "arg2"
    required: false
    default: 'default value 2'
runs:
  using: "composite"
  steps:
    - name: print arg1
      run: 'echo "print arg1 value: ${{ inputs.arg1 }} "'
      shell: bash
    - name: print arg2
      run: 'echo "print arg2 value: ${{ inputs.arg2 }} "'
      shell: bash

Composite with outputs

1
2
3
4
5
6
7
```bash
.github
    ├── actions
       └── action_output
           └── action.yaml
    └── workflows
        └── demo.yml
workflows/demo.yml
name: demos
on: [workflow_dispatch]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: call action that return output
        id: call_action
        uses: ./.github/actions/action_output
      - name: use the output
        run: 'echo "print output value: ${{ steps.call_action.outputs.my_output }} "'
        shell: bash
actions/action_output/action.yaml
name: "my output demo"
description: "return output from action"
outputs:
  my_output:
    description: "my output"
    value: ""
runs:
  using: "composite"
  steps:
    - name: calc output
      run: echo "my_output=my output value from sub action" >> $GITHUB_OUTPUT
      shell: bash

usage

act -j test --bind --directory . --pull=false