Replace Jenkinsfile with GitHub Actions CI, release and lint tooling
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
# A CVE published after a merge is still our problem, so rescan daily.
|
||||
schedule:
|
||||
- cron: "0 4 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A push supersedes the run of the commit before it, so drop that one instead of
|
||||
# waiting for a verdict on code nobody has any more.
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
go:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- run: gofmt -l cmd lib | tee /dev/stderr | (! read -r)
|
||||
- run: go mod tidy -diff
|
||||
- run: go vet ./...
|
||||
- run: go test -race ./...
|
||||
- run: make build
|
||||
# Read from a plain file so the upstream-sync workflow can bump it without a
|
||||
# token carrying the workflow scope.
|
||||
- id: lint-version
|
||||
run: echo "version=$(cat hack/golangci-lint.version)" >> "$GITHUB_OUTPUT"
|
||||
- uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: ${{ steps.lint-version.outputs.version }}
|
||||
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
# Reachability-aware, so it only fails on vulnerabilities we actually call.
|
||||
# It installs its own Go, hence no setup-go step; go-version-input must be
|
||||
# cleared or it collides with go-version-file.
|
||||
- uses: golang/govulncheck-action@v1.1.0
|
||||
with:
|
||||
repo-checkout: false
|
||||
go-version-file: go.mod
|
||||
go-version-input: ""
|
||||
- uses: aquasecurity/trivy-action@v0.36.0
|
||||
with:
|
||||
scan-type: fs
|
||||
scan-ref: .
|
||||
scanners: vuln,secret
|
||||
format: table
|
||||
exit-code: "1"
|
||||
ignore-unfixed: true
|
||||
severity: CRITICAL,HIGH
|
||||
|
||||
image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
- uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
push: false
|
||||
load: true
|
||||
tags: routingtabletowg:ci
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
- uses: aquasecurity/trivy-action@v0.36.0
|
||||
with:
|
||||
image-ref: routingtabletowg:ci
|
||||
format: table
|
||||
exit-code: "1"
|
||||
ignore-unfixed: true
|
||||
severity: CRITICAL,HIGH
|
||||
@@ -0,0 +1,68 @@
|
||||
name: release
|
||||
|
||||
# 1.2.3 is a release, anything with a suffix (1.2.3-rc.1) a prerelease. The tags
|
||||
# carry no v prefix.
|
||||
on:
|
||||
push:
|
||||
tags: ["[0-9]+.[0-9]+.[0-9]+*"]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
# Emulation for the RUN steps of the non-native platforms.
|
||||
- uses: docker/setup-qemu-action@v4
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
- uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
# The tag is v-less already, so {{version}} is the tag itself. major.minor and
|
||||
# major are skipped for prereleases by the action itself.
|
||||
- id: meta
|
||||
uses: docker/metadata-action@v6
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
- uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
sbom: true
|
||||
provenance: mode=max
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: image
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Create the GitHub release
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
flags=()
|
||||
case "${GITHUB_REF_NAME}" in
|
||||
*-*) flags+=(--prerelease) ;;
|
||||
# Notes for a stable release span back to the previous stable tag in its
|
||||
# history, not to the last RC or a newer release on another branch.
|
||||
*)
|
||||
prev=$(git describe --tags --abbrev=0 --match '[0-9]*' --exclude '*-*' "${GITHUB_REF_NAME}^" 2>/dev/null || true)
|
||||
[ -n "${prev}" ] && flags+=(--notes-start-tag "${prev}")
|
||||
;;
|
||||
esac
|
||||
gh release create "${GITHUB_REF_NAME}" --verify-tag --generate-notes "${flags[@]}"
|
||||
@@ -0,0 +1,75 @@
|
||||
# The golangci-lint version lives in hack/golangci-lint.version, which Dependabot
|
||||
# cannot parse. This bumps it and opens a PR.
|
||||
#
|
||||
# Events caused by GITHUB_TOKEN start no workflows. AUTOMATION_SSH_KEY is an optional
|
||||
# repository secret holding the private half of a deploy key with write access; the
|
||||
# branch is pushed over SSH with it, so pushes to an open PR run ci.yaml. Opening the PR
|
||||
# is still a GITHUB_TOKEN event, so a new PR gets its checks from a dispatched run on
|
||||
# its branch, as workflow_dispatch is the exception to that rule.
|
||||
name: upstream-sync
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "17 4 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
golangci-lint:
|
||||
runs-on: ubuntu-latest
|
||||
concurrency:
|
||||
group: upstream-sync-golangci-lint
|
||||
cancel-in-progress: true
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
ssh-key: ${{ secrets.AUTOMATION_SSH_KEY }}
|
||||
|
||||
- id: detect
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
current=$(cat hack/golangci-lint.version)
|
||||
latest=$(gh release view --repo golangci/golangci-lint --json tagName -q .tagName)
|
||||
echo "current=${current}" >> "$GITHUB_OUTPUT"
|
||||
echo "latest=${latest}" >> "$GITHUB_OUTPUT"
|
||||
[ "${current}" = "${latest}" ] && echo "changed=false" >> "$GITHUB_OUTPUT" || echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- if: steps.detect.outputs.changed == 'true'
|
||||
run: echo "${{ steps.detect.outputs.latest }}" > hack/golangci-lint.version
|
||||
|
||||
# A new release usually means new checks, so let the PR say whether we pass.
|
||||
- if: steps.detect.outputs.changed == 'true'
|
||||
id: lint
|
||||
continue-on-error: true
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: ${{ steps.detect.outputs.latest }}
|
||||
|
||||
- if: steps.detect.outputs.changed == 'true'
|
||||
id: pr
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
with:
|
||||
branch: automation/golangci-lint-version-sync
|
||||
delete-branch: true
|
||||
commit-message: "Bump golangci-lint to ${{ steps.detect.outputs.latest }}"
|
||||
title: "Bump golangci-lint to ${{ steps.detect.outputs.latest }}"
|
||||
body: |
|
||||
Automated golangci-lint upstream sync.
|
||||
|
||||
- Previous: `${{ steps.detect.outputs.current }}`
|
||||
- New: `${{ steps.detect.outputs.latest }}`
|
||||
|
||||
Result of running the new version against the tree: `${{ steps.lint.outcome }}`.
|
||||
A failure here is expected when a release adds checks; the findings are in the
|
||||
job log of the run that opened this PR.
|
||||
|
||||
- if: steps.pr.outputs.pull-request-operation == 'created'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: gh workflow run ci.yaml --ref automation/golangci-lint-version-sync
|
||||
Reference in New Issue
Block a user