From 9c4675a227e0469aa2e6af6df30b1720f1685c65 Mon Sep 17 00:00:00 2001 From: surskitt Date: Sun, 1 Sep 2024 00:53:59 +0100 Subject: [PATCH] feat(actions): switch to ko for release action --- .github/workflows/release.yaml | 137 ++++++++------------------------- 1 file changed, 34 insertions(+), 103 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1496793..62484ba 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,159 +8,90 @@ on: - main paths: - '*.go' - - Dockerfile - go.mod - go.sum pull_request: paths: - '*.go' - - Dockerfile - go.mod - go.sum + - .github/workflows/*.yaml jobs: - hadolint: - name: Run hadolint - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: hadolint - uses: reviewdog/action-hadolint@v1.25.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-pr-review - filter_mode: diff_context - fail_on_error: true - gotest: name: Go test runs-on: ubuntu-20.04 + steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.21 - name: Test run: go test -v ./... - build: name: Build runs-on: ubuntu-20.04 needs: - - hadolint - gotest + # - e2e + if: "!contains(github.event.head_commit.message, '[ci-skip]')" + + steps: + name: Build + runs-on: ubuntu-20.04 + needs: + - gotest + # - e2e if: "!contains(github.event.head_commit.message, '[ci-skip]')" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install GitVersion - uses: gittools/actions/gitversion/setup@v0.9.10 + uses: gittools/actions/gitversion/setup@v0.10.2 with: versionSpec: '5.x' - name: GitVersion id: gitversion - uses: gittools/actions/gitversion/execute@v0.9.10 + uses: gittools/actions/gitversion/execute@v0.10.2 - name: Prepare id: prep run: | - if test -f "./goss.yaml"; then - echo ::set-output name=goss::true - else - echo ::set-output name=goss::false - fi - if [ "${{github.event_name}}" == "pull_request" ]; then - echo ::set-output name=push::false - echo ::set-output name=cache_from::"type=local,src=/tmp/.buildx-cache" - echo ::set-output name=cache_to::"" + echo ::set-output name=PUSH::false else - echo ::set-output name=push::true - echo ::set-output name=cache_from::"type=local,src=/tmp/.buildx-cache" - echo ::set-output name=cache_to::"type=local,dest=/tmp/.buildx-cache,mode=max" + echo ::set-output name=PUSH::true fi - echo ::set-output name=gitversionf::${GITVERSION_FULLSEMVER/+/-} + echo ::set-output name=GITVERSIONF::${GITVERSION_FULLSEMVER/+/-} - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: amd64,arm64 - - - name: Login to GHCR - uses: docker/login-action@v1 - if: github.event_name != 'pull_request' - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Install and configure Buildx - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 + - name: Set up Go + uses: actions/setup-go@v5 with: - install: true - version: latest - driver-opts: image=moby/buildkit:latest + go-version: 1.21 - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: docker-cache - restore-keys: docker-cache - - # Install the GOSS testing framework - - name: Set up goss/dgoss - uses: e1himself/goss-installation-action@v1.0.4 - if: ${{ steps.prep.outputs.goss == 'true' }} - with: - version: 'v0.3.16' + - name: Setup ko + uses: imjasonh/setup-ko@v0.6 - # Creates a local build to run tests on - - name: Build and Load local test-container - if: ${{ steps.prep.outputs.goss == 'true' }} - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - load: true - tags: | - ghcr.io/${{ github.repository_owner }}/${{ matrix.container }}:test - cache-from: ${{ steps.prep.outputs.cache_from }} - cache-to: ${{ steps.prep.outputs.cache_to }} - - # Run GOSS tests if included with the container - - name: Run GOSS tests - if: ${{ steps.prep.outputs.goss == 'true' }} - env: - GOSS_FILE: ./goss.yaml - run: | - dgoss run ghcr.io/${{ github.repository_owner }}/${{ matrix.container }}:test + - name: Build local image + run: > + ko build --bare --platform linux/amd64,linux/arm64 + --sbom none --tags latest,${{ steps.prep.outputs.GITVERSIONF }} --push=false . + if: ${{ steps.prep.outputs.PUSH == 'false' }} - # Push if not a PR, otherwise just test the build process for all requested platforms - - name: Build and Push - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/amd64,linux/arm64 - file: ./Dockerfile - push: ${{ steps.prep.outputs.push }} - tags: | - ghcr.io/${{ github.repository_owner }}/gowon-retroachievements:latest - ghcr.io/${{ github.repository_owner }}/gowon-retroachievements:${{ steps.prep.outputs.gitversionf }} - cache-from: ${{ steps.prep.outputs.cache_from }} - cache-to: ${{ steps.prep.outputs.cache_to }} + - name: Build and push image + run: > + ko build --bare --platform linux/amd64,linux/arm64 + --sbom none --tags latest,${{ steps.prep.outputs.GITVERSIONF }} . + if: ${{ steps.prep.outputs.PUSH == 'true' }}