Update github actions #977
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
env: | |
# renovate: datasource=go depName=github.com/golangci/golangci-lint | |
GOLANGCI_LINT_VERSION: "v1.59.0" | |
jobs: | |
test: | |
name: Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup Go | |
uses: ./.github/actions/setup-go | |
with: | |
cache-name: test | |
- name: Pull docker images | |
run: | | |
docker pull ghcr.io/zikaeroh/postgres-initialized:16 | |
docker pull nsqio/nsq | |
- name: Run tests | |
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0 | |
with: | |
timeout_minutes: 15 | |
max_attempts: 5 | |
command: GOEXPERIMENT=nocoverageredesign go test -race -covermode=atomic -coverprofile=coverage.txt -coverpkg=./... ./... | |
on_retry_command: go clean -testcache | |
- name: Run 1x benchmarks | |
run: go test -run=- -bench . -benchtime=1x ./... | |
- name: Upload coverage report | |
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} # required | |
file: ./coverage.txt | |
style: | |
name: Style | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup Go | |
uses: ./.github/actions/setup-go | |
with: | |
cache-name: style | |
- name: Check go.mod tidyness | |
run: | | |
go mod tidy | |
git diff --exit-code go.mod go.sum | |
- name: golangci-lint | |
run: | | |
go run github.com/golangci/golangci-lint/cmd/golangci-lint@${{ env.GOLANGCI_LINT_VERSION }} run --timeout 10m | |
generate: | |
name: go generate | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup Go | |
uses: ./.github/actions/setup-go | |
with: | |
cache-name: generate | |
- name: go generate | |
run: | | |
go generate ./... | |
git diff --exit-code | |
- name: genmodels | |
run: | | |
go run ./internal/cmd/genmodels | |
git diff --exit-code | |
ko: | |
name: Ko | |
runs-on: ubuntu-latest | |
needs: [test, style, generate] | |
concurrency: ko-${{ github.ref }} | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
fetch-depth: 0 | |
- name: Get version | |
id: version | |
run: | | |
HB_VERSION="r$(git rev-list --count HEAD).$(git rev-parse --short HEAD)" | |
echo Version $HB_VERSION | |
echo "version=$HB_VERSION" >> "$GITHUB_OUTPUT" | |
- name: Setup Go | |
uses: ./.github/actions/setup-go | |
with: | |
cache-name: ko | |
- uses: imjasonh/setup-ko@3aebd0597dc1e9d1a26bcfdb7cbeb19c131d3037 # v0.7 | |
# TODO: Let ko push directly to registry? (Need to find a way to omit the hash-based tags.) | |
- name: Build image | |
id: ko | |
run: | | |
export HB_VERSION="${{ steps.version.outputs.version }}" | |
KO_IMAGE=$(ko publish --local --preserve-import-paths .) | |
echo $KO_IMAGE | |
echo "image=$KO_IMAGE" >> $GITHUB_OUTPUT | |
- name: Check version | |
run: | | |
GOT_HB_VERSION=$(docker run ${{ steps.ko.outputs.image }} version) | |
echo $GOT_HB_VERSION | |
[[ "$GOT_HB_VERSION" = "${{ steps.version.outputs.version }}" ]] | |
- name: Docker login | |
if: ${{ github.repository == 'hortbot/hortbot' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push image to GitHub | |
if: ${{ github.repository == 'hortbot/hortbot' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
run: | | |
docker tag ${{ steps.ko.outputs.image }} ghcr.io/hortbot/hortbot:latest | |
docker tag ${{ steps.ko.outputs.image }} ghcr.io/hortbot/hortbot:${{ steps.version.outputs.version }} | |
docker push ghcr.io/hortbot/hortbot:latest | |
docker push ghcr.io/hortbot/hortbot:${{ steps.version.outputs.version }} |