Skip to content

Commit

Permalink
switch to using reusable workflows (#149)
Browse files Browse the repository at this point in the history
While at it also make testing jobs faster by caching more aggressively
  • Loading branch information
capnspacehook authored Sep 22, 2023
1 parent acb536c commit 2629561
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 290 deletions.
28 changes: 4 additions & 24 deletions .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,7 @@ on:
workflow_dispatch: {}

jobs:
check-go-generate:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Ensure 'go generate' is clean
run: |
# shellcheck disable=SC2046
go generate $(go list ./...)
echo
echo
if ! git diff --name-only --exit-code; then
echo "The files above need updating. Please run 'go generate'."
exit 1
fi
check-generated:
permissions:
contents: read
uses: capnspacehook/go-workflows/.github/workflows/check-generated.yml@master
42 changes: 4 additions & 38 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CodeQL
name: Run CodeQL

on:
push:
Expand All @@ -13,43 +13,9 @@ on:
workflow_dispatch: {}

jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 15
codeql:
permissions:
actions: read
actions: write
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language:
- go

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
uses: capnspacehook/go-workflows/.github/workflows/codeql.yml@master
20 changes: 3 additions & 17 deletions .github/workflows/lint-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ on:

jobs:
lint-workflows:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Lint workflow files
run: |
echo "::add-matcher::.github/actionlint-matcher.json"
go install github.com/rhysd/actionlint/cmd/actionlint@latest
actionlint
permissions:
contents: read
uses: capnspacehook/go-workflows/.github/workflows/lint-actions.yml@master
13 changes: 3 additions & 10 deletions .github/workflows/lint-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ on:

jobs:
lint-dockerfile:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
permissions:
contents: read
uses: capnspacehook/go-workflows/.github/workflows/lint-docker.yml@master
63 changes: 4 additions & 59 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,7 @@ on:
workflow_dispatch: {}

jobs:
check-mod-tidy:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
id: install-go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Ensure go.mod was tidied
run: |
go mod tidy -compat ${{ steps.install-go.outputs.go-version }}
STATUS=$(git status --porcelain go.mod go.sum)
if [ -n "$STATUS" ]; then
echo "Running go mod tidy modified go.mod and/or go.sum"
exit 1
fi
exit 0
staticcheck:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
id: install-go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Lint with staticcheck
uses: dominikh/[email protected]
with:
install-go: false

golangci-lint:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
id: install-go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Lint with golangci-lint
uses: golangci/[email protected]
lint-go:
permissions:
contents: read
uses: capnspacehook/go-workflows/.github/workflows/lint-go.yml@master
121 changes: 2 additions & 119 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,126 +8,9 @@ on:
- "v*.*.*"

jobs:
release-binary:
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
timeout-minutes: 15
release:
permissions:
id-token: write
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout tags
run: git fetch --force --tags

- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true

- name: Install cosign
uses: sigstore/cosign-installer@main

- name: Build and release with goreleaser
uses: goreleaser/goreleaser-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
distribution: goreleaser
version: latest
args: release

release-image:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
id-token: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install cosign
uses: sigstore/cosign-installer@v3

- name: Install Docker buildx
uses: docker/setup-buildx-action@v3

- name: Build list of Docker tags to use
id: tag-types
run: |
if [[ ${{ contains(github.ref, 'tag') }} == true ]]; then
TAGS="
type=semver,pattern={{major}},priority=920
type=semver,pattern={{major}}.{{minor}},priority=910
type=semver,pattern={{version}},priority=900
type=ref,event=branch
type=sha,format=long"
else
TAGS="
type=ref,event=branch
type=sha,format=long"
fi
# https://trstringer.com/github-actions-multiline-strings
{
echo "TAGS<<EOF"
echo "$TAGS"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Set Docker labels and tags
id: metadata
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=true
tags: ${{ env.TAGS }}

- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get latest git tag
id: get-tag
uses: olegtarasov/[email protected]

- name: Set build arguments
id: build-args
run: |
VERSION=${{ steps.get-tag.outputs.tag }}
if [[ -z ${VERSION} ]]; then
VERSION=devel
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: |
VERSION=${{ steps.build-args.outputs.version }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

- name: Sign container image
env:
COSIGN_EXPERIMENTAL: "true"
run: cosign sign --yes ghcr.io/${{ github.repository }}@${{ steps.build-push.outputs.digest }}

- name: Scan container image for vulnerabilities
uses: chainguard-images/actions/vul-scans@main
with:
image: ghcr.io/${{ github.repository }}@${{ steps.build-push.outputs.digest }}
RUN_SNYK: false
uses: capnspacehook/go-workflows/.github/workflows/release.yml@master
21 changes: 15 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:

workflow_dispatch: {}

permissions:
contents: read

jobs:
race-test:
# required for nftables to work correctly
Expand All @@ -20,10 +23,12 @@ jobs:
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
uses: WillAbides/setup-go[email protected]
with:
go-version-file: go.mod
check-latest: true

- name: Cache Go files
uses: capnspacehook/cache-go@v1

# the test is compiled and run as root so that whalewall can
# interface with nftables, which is a privileged operation
Expand All @@ -39,10 +44,12 @@ jobs:
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
uses: WillAbides/setup-go[email protected]
with:
go-version-file: go.mod
check-latest: true

- name: Cache Go files
uses: capnspacehook/cache-go@v1

# run the integration tests but use a binary to create rules
# to test with landlock and seccomp filters active
Expand Down Expand Up @@ -71,10 +78,12 @@ jobs:
tags: whalewall:test

- name: Install Go
uses: actions/setup-go@v4
uses: WillAbides/setup-go[email protected]
with:
go-version-file: go.mod
check-latest: true

- name: Cache Go files
uses: capnspacehook/cache-go@v1

# run the integration tests but use a container to create rules
# to test with landlock and seccomp filters active
Expand Down
Loading

0 comments on commit 2629561

Please sign in to comment.