From fcec01d56ce2f8996469998369c521bceb0d2b87 Mon Sep 17 00:00:00 2001 From: Joshua Rich Date: Sun, 26 May 2024 14:21:46 +1000 Subject: [PATCH] ci(github): :construction_worker: more mage utilisation in github actions --- .github/workflows/build.yml | 75 ++++++++---------------------------- .github/workflows/codeql.yml | 12 +++--- .github/workflows/test.yml | 23 +++++------ 3 files changed, 31 insertions(+), 79 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a50b3dfb9..549f23cdc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,7 @@ permissions: env: GO_VERSION: 1.22 + MAGEARGS: "-v -d build/magefiles -w ." jobs: check_release: @@ -27,7 +28,7 @@ jobs: - name: Harden Runner uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v1 with: - egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: Run release please uses: googleapis/release-please-action@v4 id: release_please @@ -40,70 +41,29 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - arch: [amd64,arm,arm64] + arch: [amd64,arm,arm64] steps: - name: Harden Runner uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v1 with: - egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: Checkout source uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up environment - run: | - # echo "APPVERSION=$(git describe --tags --abbrev=0)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV - echo "BUILD_ENV=build/env.${{ matrix.arch }}" >> $GITHUB_ENV - # - name: Set app version for release - # if: ${{ needs.check_release.outputs.release_created }} - # run: echo "APPVERSION=${{ needs.check_release.outputs.release_tag }}" >> $GITHUB_ENV - - name: Add ${{ matrix.arch }} package repos - if: ${{ matrix.arch != 'amd64' }} - id: enable_multiarch - run: build/scripts/enable-multiarch - - name: Install build dependencies - id: install_packages - run: build/scripts/install-deps - name: Setup Go id: setup_go uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - name: Install Go dependencies - id: install_go_deps - run: | - go install golang.org/x/tools/cmd/stringer@latest - go install golang.org/x/text/cmd/gotext@latest - go install github.com/matryer/moq@latest - go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest - go install github.com/fyne-io/fyne-cross@latest - - name: Build ${{ matrix.arch }} binary - id: build_binary - shell: bash - run: | - source ${BUILD_ENV} - echo ARCH: ${MATRIX_ARCH} CC: ${CC} GOARCH: ${GOARCH} PKG_CONFIG_PATH: ${PKG_CONFIG_PATH} - go generate -v ./... - go build -ldflags "${LDFLAGS}" -v -o dist/go-hass-agent-${{ matrix.arch }} - env: - CGO_ENABLED: 1 - MATRIX_ARCH: ${{ matrix.arch }} - - name: Build with fyne-cross - id: build_fyne_cross - shell: bash - run: | - fyne-cross linux -arch=${{ matrix.arch }} -name go-hass-agent \ - -icon internal/agent/ui/assets/logo-pretty.png -release - mv fyne-cross/dist/linux-${{ matrix.arch }}/go-hass-agent.tar.xz \ - fyne-cross/dist/linux-${{ matrix.arch }}/go-hass-agent-${{ matrix.arch }}.tar.xz - - name: Create packages - id: nfpm_package - shell: bash - run: | - source ${BUILD_ENV} - nfpm package --config .nfpm.yaml --packager rpm --target dist - nfpm package --config .nfpm.yaml --packager deb --target dist - nfpm package --config .nfpm.yaml --packager archlinux --target dist + - name: Install Mage + uses: magefile/mage-action@v3 + with: + install-only: true + - name: Build with Mage + run: mage ${MAGEARGS} build:ci ${{ matrix.arch }} + - name: Package with Mage + run: mage ${MAGEARGS} package:ci ${{ matrix.arch }} - name: Install cosign id: cosign_install uses: sigstore/cosign-installer@v3.5.0 @@ -128,14 +88,14 @@ jobs: with: name: build-${{ matrix.arch }}-${{ github.sha }} path: | - dist + dist fyne-cross/dist/linux-${{ matrix.arch }} - name: Upload release artifacts id: upload_release if: ${{ needs.check_release.outputs.release_created }} run: | - gh release upload ${{ needs.check_release.outputs.release_tag }} dist/*.{rpm,deb,zst,sig} - gh release upload ${{ needs.check_release.outputs.release_tag }} fyne-cross/dist/linux-${{ matrix.arch }}/* + gh release upload ${{ needs.check_release.outputs.release_tag }} dist/*.{rpm,deb,zst,sig} + gh release upload ${{ needs.check_release.outputs.release_tag }} fyne-cross/dist/linux-${{ matrix.arch }}/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -153,7 +113,7 @@ jobs: # - linux/arm64 env: REGISTRY: ghcr.io - IMAGE: ${{ github.repository }} + IMAGE: ${{ github.repository }} steps: - uses: GitHubSecurityLab/actions-permissions/monitor@v1 with: @@ -163,7 +123,7 @@ jobs: with: fetch-depth: 0 - name: Set up environment - run: | + run: | echo "APPVERSION=$(git describe --tags --abbrev=0)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV # platform=${{ matrix.platform }} # echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV @@ -224,4 +184,3 @@ jobs: -a "repo=${{ github.repository }}" \ -a "ref=${{ github.ref }}" \ ${images} - \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fc3f064c1..1efdcf974 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,7 +13,8 @@ permissions: env: GO_VERSION: 1.22 - ARCH: amd64 + ARCH: amd64 + MAGEARGS: -v -d build/magefiles -w . jobs: analyze: @@ -34,14 +35,11 @@ jobs: - name: Harden Runner uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v1 with: - egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up environment - run: | - echo "BUILD_ENV=build/env.$ARCH" >> $GITHUB_ENV - name: Install build dependencies id: install_packages run: build/scripts/install-deps @@ -55,7 +53,7 @@ jobs: with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} - packs: githubsecuritylab/codeql-${{ matrix.language }}-queries + packs: githubsecuritylab/codeql-${{ matrix.language }}-queries - if: matrix.build-mode == 'manual' name: Install Mage uses: magefile/mage-action@v3 @@ -63,7 +61,7 @@ jobs: install-only: true - if: matrix.build-mode == 'manual' name: Build with Mage - run: mage -d build/magefiles -w . build:full ${ARCH} + run: mage ${MAGEARGS} build:full ${ARCH} - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09718ca2c..c4f39d23f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,7 @@ permissions: env: GO_VERSION: 1.22 ARCH: amd64 + MAGEARGS: "-v -d build/magefiles -w ." jobs: test: @@ -20,18 +21,12 @@ jobs: - name: Harden Runner uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v1 with: - egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: Checkout id: checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up environment - run: | - echo "BUILD_ENV=build/env.$ARCH" >> $GITHUB_ENV - - name: Install build dependencies - id: install_packages - run: build/scripts/install-deps - name: Set up Go id: setup_go uses: actions/setup-go@v5 @@ -42,7 +37,7 @@ jobs: with: install-only: true - name: Run tests - run: mage -d build/magefiles -w . tests:test + run: mage ${MAGEARGS} tests:ci ${ARCH} continue-on-error: true - name: Upload Coverage id: upload_coverage @@ -66,12 +61,12 @@ jobs: with: go-version: ${{ env.GO_VERSION }} cache: false # golangci-lint maintains its own cache - - name: Set up environment - run: | - echo "BUILD_ENV=build/env.$ARCH" >> $GITHUB_ENV - - name: Install build dependencies - id: install_packages - run: build/scripts/install-deps + - name: Install Mage + uses: magefile/mage-action@v3 + with: + install-only: true + - name: Install build deps + run: mage ${MAGEARGS} preps:deps ${ARCH} - name: golangci-lint uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 with: