Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: migrate publish container workflow to GHA #844

Draft
wants to merge 6 commits into
base: gha-push-pr
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/publish-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish container

permissions:
# Needed to assume roles from Github's OIDC.
contents: read
id-token: write
# Needed to push to ghcr.
packages: write

on:
push:
branches:
- 'main'
# FIXME: FOR TESTING ONLY. DELETE BEFORE MERGING.
- 'gha-publish-container'
tags:
- 'v*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: grafana/shared-workflows/actions/dockerhub-login@main
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for the version script to work.
- name: Compute repo metadata
id: repo
run: |-
echo "name=$(basename '${{ github.repository }}')" >> $GITHUB_OUTPUT
echo "version=$(./scripts/version)" >> $GITHUB_OUTPUT
echo "version-short=$(./scripts/version short)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
# TODO: Make Dockerfile selfcontained. For now we need to build binaries on the host.
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build
run: |
make build
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build and push container
uses: docker/build-push-action@v6
with:
push: false # FIXME: For testing, should be `true`.
platforms: linux/amd64,linux/arm64
# Needed for this action to use local context incl. binaries built in the previous step.
# https://github.com/docker/build-push-action?tab=readme-ov-file#path-context
# TODO: Make docker build self-contained.
context: .
tags: |-
docker.io/${{ github.repository}}:latest
docker.io/${{ github.repository}}:${{ steps.repo.outputs.version }}
docker.io/${{ github.repository}}:${{ steps.repo.outputs.version-short }}
ghcr.io/${{ github.repository}}:${{ steps.repo.outputs.version-short }}
81 changes: 81 additions & 0 deletions .github/workflows/push-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Push/PR

on:
pull_request: {}
push:
branches:
- main

jobs:
deps:
name: Check dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Ensure deps are clean
run: |
make deps
./scripts/enforce-clean

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for version script to work.
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build
run: |
make build
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build container
uses: docker/build-push-action@v6
with:
push: false
platforms: linux/amd64,linux/arm64
# Needed for this action to use local context incl. binaries built in the previous step.
# https://github.com/docker/build-push-action?tab=readme-ov-file#path-context
# TODO: Make docker build self-contained.
context: .
tags: ci.local/${{ github.repository }}

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Test
run: |
make build-xk6-linux-amd64 # Tests require a valid k6 binary in dist/k6
make test

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Get golangci-lint version that `make lint` uses.
- name: Retrieve golangci-lint version
id: version
run: |-
echo "golangci=$(make golangci-lint-version)" >> $GITHUB_OUTPUT
# Use the golangci-lint action, which provides Github-specific features such as diff annotations.
- name: Run golangi-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ steps.version.outputs.golangci }}
args: --timeout=5m # 1m is not enough, experimentally.
only-new-issues: true
- name: Run the rest of the linters
run: |-
make lint GOLANGCI_LINT=/bin/true
File renamed without changes.
6 changes: 5 additions & 1 deletion scripts/make/linters.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ golangci-lint: $(if $(filter $(LOCAL_GOLANGCI_LINT),yes),$(GOLANGCI_LINT))
$(S) echo "lint via golangci-lint"
$(S) $(GOLANGCI_LINT) run \
$(GOLANGCI_LINT_MOD_FLAGS) \
--config ./scripts/configs/golangci.yml \
--config ./golangci.yml \
--verbose \
--verbose \
$(GO_PKGS)

.PHONY: golangci-lint-version
golangci-lint-version:
$(S) $(GOLANGCI_LINT) version --format short

.PHONY: go-vet
go-vet:
$(S) echo "lint via go vet"
Expand Down
7 changes: 6 additions & 1 deletion scripts/version
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/sh

git describe --dirty --tags --long --always
args=""
if [ "$1" != "short" ]; then
args="--long"
fi

git describe --dirty --tags --always $args
Loading