From 13d9331fb3f555cca3080482119272a7ae27a791 Mon Sep 17 00:00:00 2001 From: JP Meijers Date: Fri, 4 Oct 2024 15:30:34 +0200 Subject: [PATCH] Auto promote to beta when tests pass (#81) Use matrix to build, publish to edge, and test on arm64 and amd64. Promote to beta when succeeded. --- .github/workflows/build-and-test-snap.yml | 134 ---------------------- .github/workflows/snap-ci.yaml | 92 +++++++++++++++ 2 files changed, 92 insertions(+), 134 deletions(-) delete mode 100644 .github/workflows/build-and-test-snap.yml create mode 100644 .github/workflows/snap-ci.yaml diff --git a/.github/workflows/build-and-test-snap.yml b/.github/workflows/build-and-test-snap.yml deleted file mode 100644 index 61d8d68..0000000 --- a/.github/workflows/build-and-test-snap.yml +++ /dev/null @@ -1,134 +0,0 @@ -name: Build, test and publish snap - -on: - schedule: - - cron: "20 2 * * 1" # Monday morning 02:20 UTC - push: - branches: [ main ] - pull_request: - branches: [ main ] - # Allow manual trigger - workflow_dispatch: - -env: - ARTIFACT_AMD64: chip-tool_${{ github.run_number}}_amd64 - ARTIFACT_ARM64: chip-tool_${{ github.run_number}}_arm64 - -jobs: - build-amd64: - outputs: - snap: ${{ steps.snapcraft.outputs.snap }} - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build snap - uses: snapcore/action-build@v1 - id: snapcraft - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ env.ARTIFACT_AMD64 }} - path: ${{ steps.snapcraft.outputs.snap }} - if-no-files-found: error - - test-amd64: - needs: build-amd64 - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - lfs: true - - - name: Download locally built snap - uses: actions/download-artifact@v4 - with: - name: ${{ env.ARTIFACT_AMD64 }} - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: '1.*' - cache: false - - - name: Run tests - shell: bash - working-directory: tests - env: - SKIP_TEARDOWN_REMOVAL: true - LOCAL_SERVICE_SNAP: ../${{ needs.build-amd64.outputs.snap }} - run: | - go test -failfast -p 1 -timeout 30m -v - - - name: Upload snap logs - if: always() - uses: actions/upload-artifact@v4 - with: - name: logs - path: tests/logs/*.log - - publish-amd64: - # Only publish if we are on the main branch - if: github.ref == 'refs/heads/main' - needs: [build-amd64, test-amd64] - runs-on: ubuntu-latest - steps: - - name: Download locally built snap - uses: actions/download-artifact@v4 - with: - name: ${{ env.ARTIFACT_AMD64 }} - - - uses: snapcore/action-publish@v1 - env: - SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} - with: - snap: ${{ needs.build-amd64.outputs.snap }} - release: latest/edge - - build-arm64: - # We do not start the long running arm64 build unless the amd64 tests have passed. - needs: test-amd64 - outputs: - snap: ${{ steps.snapcraft.outputs.snap }} - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: arm64 - - - name: Build snap - uses: diddlesnaps/snapcraft-multiarch-action@v1 - id: snapcraft - with: - architecture: arm64 - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ env.ARTIFACT_ARM64 }} - path: ${{ steps.snapcraft.outputs.snap }} - - publish-arm64: - # Only publish if we are on the main branch - if: github.ref == 'refs/heads/main' - needs: [build-arm64] - runs-on: ubuntu-latest - steps: - - name: Download locally built snap - uses: actions/download-artifact@v4 - with: - name: ${{ env.ARTIFACT_ARM64 }} - - - uses: snapcore/action-publish@v1 - env: - SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} - with: - snap: ${{ needs.build-arm64.outputs.snap }} - release: latest/edge diff --git a/.github/workflows/snap-ci.yaml b/.github/workflows/snap-ci.yaml new file mode 100644 index 0000000..0febcf1 --- /dev/null +++ b/.github/workflows/snap-ci.yaml @@ -0,0 +1,92 @@ +name: Snap CI + +on: + schedule: + - cron: "20 2 * * 1" # Monday mornings 02:20 UTC + push: + branches: [main] + pull_request: + branches: [main] + # Allow manual trigger + workflow_dispatch: + +env: + SNAP_NAME: chip-tool + +jobs: + build: + name: Build, Test, Publish + strategy: + matrix: + runs: + - architecture: amd64 + runner: ubuntu-latest + - architecture: arm64 + runner: [self-hosted, ARM64, Linux] + runs-on: ${{ matrix.runs.runner }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build snap + uses: snapcore/action-build@v1 + id: snapcraft + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{env.SNAP_NAME}}_${{github.run_number}}_${{matrix.runs.architecture}} + path: ${{ steps.snapcraft.outputs.snap }} + if-no-files-found: error + + - name: Publish snap to edge + uses: snapcore/action-publish@v1 + if: github.ref == 'refs/heads/main' + env: + SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} + with: + snap: ${{ steps.snapcraft.outputs.snap }} + release: latest/edge + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.*" + cache: false + + - name: Run tests + shell: bash + working-directory: tests + env: + TEARDOWN: false + SNAP_PATH: ../${{ steps.snapcraft.outputs.snap }} + run: | + go test -failfast -p 1 -timeout 30m -v + + - name: Upload snap logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: logs_${{ github.run_number}}_${{matrix.runs.architecture}} + path: tests/logs/*.log + + promote-beta: + name: Promote to Beta + # Only promote if we are on the main branch + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + needs: [build] + steps: + - name: Install Snapcraft + run: | + sudo snap install snapcraft --classic + echo /snap/bin >> $GITHUB_PATH + shell: bash + + - name: Promote Snap + env: # Workaround for https://github.com/snapcore/snapcraft/issues/4439 + SNAPCRAFT_HAS_TTY: "true" + SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} + run: | + yes | snapcraft promote $SNAP_NAME --from-channel latest/edge --to-channel latest/beta