#Coming from GitHub Actions
Hod looks like GitHub Actions on purpose, but it isn't compatible with it, and there's no converter. The main differences: each job names an image instead of a runner VM, the checkout is automatic, expressions are CEL, and caching and artifacts are keys of a step or job instead of actions.
| GitHub Actions | Hod |
|---|---|
on: push: branches: [main] | the same |
on: pull_request: | pull_request: {} |
runs-on: ubuntu-latest | image: <an image with your tools> |
uses: actions/checkout@v4 | nothing: every job starts with a copy of the repository |
uses: actions/setup-go@v5 with go-version | image: golang:1.23 |
uses: actions/cache@v4 with path and key: ...hashFiles(...) | cache: [go], or cache: [{paths: [...], key_files: [...]}] |
| (nothing) | cache.inputs on a step: skip it when its inputs didn't change |
actions/upload-artifact and download-artifact | files: on a step; jobs that needs it get them |
needs: [test] | the same |
env: | the same, on jobs and steps |
working-directory: web | dir: web |
if: github.event_name == 'push' | if: event.type == "push" |
startsWith(github.ref, 'refs/heads/release/') | event.branch.startsWith("release/") |
contains(github.event.pull_request.labels.*.name, 'ci') | "ci" in event.pull_request.labels |
${{ github.sha }} in run: | "$HOD_SHA" in the script; other values through env: {TITLE: "${{ event.pull_request.title }}"}, then "$TITLE" |
GITHUB_SHA, GITHUB_REF, GITHUB_REF_NAME | HOD_SHA, HOD_REF, HOD_BRANCH or HOD_TAG |
github.base_ref, GITHUB_BASE_REF | event.pull_request.base_branch, HOD_BASE_BRANCH |
dorny/paths-filter | changed("src/**", "go.mod") |
needs.build.result == 'failure' | jobs.build.result == "failure" |
strategy: {matrix: {os: [a, b]}, fail-fast: false} | matrix: {os: [a, b]} (fail_fast is off unless set); several entries are a list: matrix: [{os: [a]}, {os: [b], go: ['1.23']}] |
strategy.matrix.include / exclude | another entry of the matrix: list |
${{ matrix.os }} | the same, as a string |
a gate job such as alls-green for branch protection | require the hod (pull_request) status |
services: {postgres: {image: postgres:16, ports: [...]}} | services: {postgres: {image: postgres:16}}; steps reach it at localhost or postgres |
${{ secrets.SLACK_TOKEN }} | secrets: [{name: SLACK_TOKEN, env: SLACK_TOKEN}] on the step |
permissions: id-token: write and a cloud's login action | identity: {audience: sts.amazonaws.com}, then the cloud's CLI with $HOD_IDENTITY_TOKEN_FILE |
timeout-minutes: 30 | timeout: 30m |
continue-on-error: true | allow_failure: true |
concurrency: {group: ..., cancel-in-progress: true} | concurrency: {group: ..., policy: cancel_other} |
on: schedule: - cron: ... | hod schedule create nightly --cron '...' on the server |
job outputs: from $GITHUB_OUTPUT | outputs: {version: string} on a step, written to $HOD_OUTPUTS/version |
a step's uses: of a third-party action | a component: uses: ./.hod/components/<name> or a published one such as hod/setup-go@v1 |
a reusable workflow (uses: org/repo/.github/workflows/x.yml@v1 on a job) | a template: uses: on the job, with: for its inputs, secrets: {its_name: YOUR_SECRET} |
environment: | not in v0 yet |
This GitHub Actions workflow:
name: ci
on:
push:
branches: [main, "release/*"]
pull_request:
jobs:
test:
runs-on: ubuntu-latest # implicit, huge VM
strategy:
matrix:
go: ["1.22", "1.23"]
services:
postgres:
image: postgres:16
env: { POSTGRES_PASSWORD: test }
ports: ["5432:5432"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- uses: actions/cache@v4 # manual cache wiring
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- run: go test ./...
env:
DATABASE_URL: postgres://postgres:test@localhost:5432/postgres
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: golangci/golangci-lint-action@v6
build:
needs: [test, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with: { go-version: "1.23" }
- run: go build -o dist/app ./cmd/app
- uses: actions/upload-artifact@v4
with: { name: app, path: dist/ }
deploy:
needs: [build]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/'))
runs-on: ubuntu-latest
environment: ${{ startsWith(github.ref, 'refs/heads/release/') && 'production' || 'staging' }}
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { name: app, path: dist/ }
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/deploy
aws-region: us-east-1
- run: ./scripts/deploy.sh "${{ github.sha }}" # ⚠ interpolated into shell
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
without its deploy environment (not in v0 yet), becomes:
version: 0
on:
push:
branches: [main, "release/*"]
pull_request: {}
vars:
is_deploy: event.type == "push" && (event.branch == "main" || event.branch.startsWith("release/"))
jobs:
test:
matrix: {go: ["1.22", "1.23"]}
image: golang:${{ matrix.go }}
cache: [go]
services:
postgres:
image: postgres:16
env: {POSTGRES_PASSWORD: test}
steps:
- run: go test ./...
env:
DATABASE_URL: postgres://postgres:test@localhost:5432/postgres
lint:
image: golangci/golangci-lint:v1.61
cache: [go]
steps:
- run: golangci-lint run
build:
needs: [test, lint]
image: golang:1.23
cache: [go]
steps:
- run: go build -o dist/app ./cmd/app
files: [dist/]
deploy:
needs: [build]
if: vars.is_deploy
image: amazon/aws-cli:2.22.0
identity: {audience: sts.amazonaws.com} # no stored AWS key
env:
AWS_ROLE_ARN: arn:aws:iam::123456789012:role/deploy
AWS_REGION: us-east-1
steps:
- run: |
export AWS_WEB_IDENTITY_TOKEN_FILE="$HOD_IDENTITY_TOKEN_FILE"
./scripts/deploy.sh "$SHA"
secrets: [{name: SLACK_TOKEN, env: SLACK_TOKEN}]
env:
SHA: ${{ event.sha }}