From 1fcce457acbef04c45c54dd5e9ac13eb7c5d5cb4 Mon Sep 17 00:00:00 2001 From: Tina Boyce <12929562+tinaboyce@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:44:24 +1000 Subject: [PATCH 1/3] fix: gha setup go cache issue [#1319] --- .github/workflows/go.yml | 23 ++--- .github/workflows/release.yml | 160 +++++++++++++++++----------------- 2 files changed, 94 insertions(+), 89 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 162c747a..3925fd45 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,14 +14,14 @@ jobs: matrix: os: [ubuntu-latest, macOS-latest, macos-12] steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go 1.x uses: actions/setup-go@v5 with: go-version: 1.21.x - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Test run: | go test -v ./... -coverprofile=${{ matrix.os }}_coverage.txt -covermode=atomic @@ -41,14 +41,14 @@ jobs: name: lint runs-on: ubuntu-latest steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go 1.x uses: actions/setup-go@v5 with: go-version: 1.21.x - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: @@ -63,14 +63,17 @@ jobs: needs: [build] steps: - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 with: name: ubuntu-latest_reports path: reports + - uses: actions/download-artifact@v4 with: name: macOS-latest_reports path: reports + - uses: actions/download-artifact@v4 with: name: macos-12_reports @@ -92,13 +95,13 @@ jobs: - macos-latest runs-on: ${{ matrix.os }} steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: 1.20.x - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 + go-version: 1.21.x - name: Install dependency required for linux builds if: matrix.os == 'ubuntu-20.04' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc804a86..f7eff44f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,11 +3,11 @@ name: release on: push: tags: - - '*' + - "*" workflow_dispatch: inputs: tag: - description: The tag to run against. This trigger only runs the MSI builder. + description: The tag to run against. This trigger runs the GoReleaser and MSI builder. required: true jobs: @@ -19,44 +19,44 @@ jobs: max-parallel: 1 matrix: os: - - ubuntu-latest - - ubuntu-20.04 - - macos-latest + - ubuntu-latest + - ubuntu-20.04 + - macos-latest runs-on: ${{ matrix.os }} if: github.event_name != 'workflow_dispatch' permissions: write-all steps: - - - name: Set up Go 1.x - uses: actions/setup-go@v5 - with: - go-version: 1.21.x - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Install dependency required for linux builds - if: matrix.os == 'ubuntu-20.04' - run: sudo apt-get update && sudo apt-get install -y libudev-dev - - - name: Add Lowercase Repository Name to Environment - run: | - echo REPOSITORY_NAME_LOWERCASE=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - - - uses: "docker/login-action@v3" - if: matrix.os == 'ubuntu-20.04' - with: - registry: "ghcr.io" - username: "${{ github.actor }}" - password: "${{ secrets.GITHUB_TOKEN }}" - - name: GoReleaser - uses: goreleaser/goreleaser-action@v6 - with: - version: latest - args: release --clean --config .goreleaser.${{ matrix.os }}.yml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - IMAGE_NAME: ${{ env.REPOSITORY_NAME_LOWERCASE }} + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Set up Go 1.x + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + + - name: Install dependency required for linux builds + if: matrix.os == 'ubuntu-20.04' + run: sudo apt-get update && sudo apt-get install -y libudev-dev + + - name: Add Lowercase Repository Name to Environment + run: | + echo REPOSITORY_NAME_LOWERCASE=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + + - uses: "docker/login-action@v3" + if: matrix.os == 'ubuntu-20.04' + with: + registry: "ghcr.io" + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + + - name: GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + version: latest + args: release --clean --config .goreleaser.${{ matrix.os }}.yml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + IMAGE_NAME: ${{ env.REPOSITORY_NAME_LOWERCASE }} windows-msi: name: Build Windows MSI and upload to release @@ -64,7 +64,7 @@ jobs: permissions: contents: write needs: [release] - if: >- # https://github.com/actions/runner/issues/491 + if: >- # https://github.com/actions/runner/issues/491 always() && (needs.release.result == 'success' || needs.release.result == 'skipped') env: @@ -72,45 +72,47 @@ jobs: BIN: ${{ github.workspace }}/.github/win-msi/src/bin WIXIMG: dactiv/wix@sha256:17d232708589641f5632f9a1ff9463ad087b192cea7b8e6012d2b47ec6af5f6c steps: - - name: Normalize tag values - run: | - if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] ; then - VER=${{ github.event.inputs.tag }} - else - VER=${GITHUB_REF/refs\/tags\//} - fi - - VERSION=${VER//v} - - echo "VER_TAG=$VER" >> $GITHUB_ENV - echo "VERSION=$VERSION" >> $GITHUB_ENV - echo "ASSET=saml2aws_${VERSION}_windows_amd64.zip" >> $GITHUB_ENV - - - name: Check out code - uses: actions/checkout@v4 - - - name: Retrieve the release asset - id: asset - uses: robinraju/release-downloader@a96f54c1b5f5e09e47d9504526e96febd949d4c2 # v1.11 - with: - repository: ${{ github.repository }} - tag: ${{ env.VER_TAG }} - fileName: ${{ env.ASSET }} - out-file-path: ${{ env.BIN }} - - - name: Unzip asset - working-directory: ${{ env.BIN }} - run: unzip "${ASSET}" - - - name: Build MSI - run: | - # container does not run as root - chmod -R o+rw "${INSTALLER}" - - cat "${INSTALLER}/wix.sh" | docker run --rm -i -e VERSION -v "${INSTALLER}:/wix" ${WIXIMG} /bin/sh - - - name: Upload the asset to the release - uses: softprops/action-gh-release@a74c6b72af54cfa997e81df42d94703d6313a2d0 # v0.2.0.6.2.0.65 / v2.0.6 - with: - tag_name: ${{ env.VER_TAG }} - files: ${{ env.INSTALLER }}/out/*.msi + - name: Normalize tag values + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] ; then + VER=${{ github.event.inputs.tag }} + else + VER=${GITHUB_REF/refs\/tags\//} + fi + + VERSION=${VER//v} + + echo "VER_TAG=$VER" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "ASSET=saml2aws_${VERSION}_windows_amd64.zip" >> $GITHUB_ENV + + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Retrieve the release asset + id: asset + uses: robinraju/release-downloader@a96f54c1b5f5e09e47d9504526e96febd949d4c2 # v1.11 + with: + repository: ${{ github.repository }} + tag: ${{ env.VER_TAG }} + fileName: ${{ env.ASSET }} + out-file-path: ${{ env.BIN }} + + - name: Unzip asset + working-directory: ${{ env.BIN }} + run: unzip "${ASSET}" + + - name: Build MSI + run: | + # container does not run as root + chmod -R o+rw "${INSTALLER}" + + cat "${INSTALLER}/wix.sh" | docker run --rm -i -e VERSION -v "${INSTALLER}:/wix" ${WIXIMG} /bin/sh + + - name: Upload the asset to the release + uses: softprops/action-gh-release@a74c6b72af54cfa997e81df42d94703d6313a2d0 # v0.2.0.6.2.0.65 / v2.0.6 + with: + tag_name: ${{ env.VER_TAG }} + files: ${{ env.INSTALLER }}/out/*.msi From 22b4d5bc0258f56a6fb70b0f824b201408027eb0 Mon Sep 17 00:00:00 2001 From: Tina Boyce <12929562+tinaboyce@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:52:40 +1000 Subject: [PATCH 2/3] chore: gha job to derive go version from go.mod --- .github/workflows/go.yml | 6 +++--- .github/workflows/release.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3925fd45..ebf36664 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: 1.21.x + go-version-file: "go.mod" - name: Test run: | @@ -47,7 +47,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: 1.21.x + go-version-file: "go.mod" - name: golangci-lint uses: golangci/golangci-lint-action@v6 @@ -101,7 +101,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: 1.21.x + go-version-file: "go.mod" - name: Install dependency required for linux builds if: matrix.os == 'ubuntu-20.04' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f7eff44f..0e440871 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: 1.21.x + go-version-file: "go.mod" - name: Install dependency required for linux builds if: matrix.os == 'ubuntu-20.04' From 36c8b29c9396399b9a5a2491d47764a335713157 Mon Sep 17 00:00:00 2001 From: Tina Boyce <12929562+tinaboyce@users.noreply.github.com> Date: Mon, 22 Jul 2024 01:01:26 +1000 Subject: [PATCH 3/3] chore: gha goreleaser wants checkout to have fetch-depth of 0 --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0e440871..7e13a39c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,6 +28,8 @@ jobs: steps: - name: Check out code into the Go module directory uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Go 1.x uses: actions/setup-go@v5