From 5aacf31a85f4ff874a334453cf8e8ca69f411e75 Mon Sep 17 00:00:00 2001 From: Ben Lebherz Date: Tue, 25 Jul 2023 21:38:07 +0200 Subject: [PATCH] =?UTF-8?q?add=20test=20job=20to=20workflow=20=F0=9F=A4=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 119 ++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 52 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 73c1582..6cd7e12 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,58 +1,73 @@ name: build on: - push: { branches: [master, main, dev/*], tags: [v*] } - pull_request: - workflow_dispatch: + push: { branches: [master, main, dev/*], tags: [v*] } + pull_request: + workflow_dispatch: jobs: - build: - runs-on: ubuntu-latest - permissions: { contents: write, packages: write } - - # cancel already in-progress jobs or runs for the current workflow - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - - env: - REGISTRY: ghcr.io - TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: { fetch-depth: 0 } - - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Go - uses: actions/setup-go@v4 - with: { cache: true, check-latest: true, go-version-file: "go.mod" } - - - name: Run GoReleaser (snapshot) - uses: goreleaser/goreleaser-action@v4 - if: "!startsWith(github.ref, 'refs/tags/')" - with: - version: latest - args: build --clean --snapshot - env: - REGISTRY: ${{ env.REGISTRY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Run GoReleaser (release) - uses: goreleaser/goreleaser-action@v4 - if: startsWith(github.ref, 'refs/tags/') - with: - version: latest - args: release --clean + build: + runs-on: ubuntu-latest + permissions: { contents: write, packages: write } + + # cancel already in-progress jobs or runs for the current workflow + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + env: - REGISTRY: ${{ env.REGISTRY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + REGISTRY: ghcr.io + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: { fetch-depth: 0 } + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Go + uses: actions/setup-go@v4 + with: { cache: true, check-latest: true, go-version-file: "go.mod" } + + - name: Run GoReleaser (snapshot) + uses: goreleaser/goreleaser-action@v4 + if: "!startsWith(github.ref, 'refs/tags/')" + with: + version: latest + args: build --clean --snapshot + env: + REGISTRY: ${{ env.REGISTRY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run GoReleaser (release) + uses: goreleaser/goreleaser-action@v4 + if: startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --clean + env: + REGISTRY: ${{ env.REGISTRY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + + test: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ["1.19", "1.20"] + + steps: + - name: Test with Go + run: go test -json > TestResults-${{ matrix.go-version }}.json + - name: Upload Go test results + uses: actions/upload-artifact@v3 + with: + name: Go-results-${{ matrix.go-version }} + path: TestResults-${{ matrix.go-version }}.json