From 734114cb38b2097c6d2aa6a3066d30ee2e07b492 Mon Sep 17 00:00:00 2001 From: Marcel Schramm Date: Sat, 19 Feb 2022 19:35:36 +0100 Subject: [PATCH] Improve build workflows * Use go 1.17.x * Separate build steps into different files * Add new build steps to publish a release upon a new tag --- .github/workflows/code-coverage-upload.yml | 31 +++++ .github/workflows/release.yml | 43 +++++++ .github/workflows/test-and-build.yml | 126 +++++---------------- .github/workflows/test-pr.yml | 2 +- 4 files changed, 106 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/code-coverage-upload.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/code-coverage-upload.yml b/.github/workflows/code-coverage-upload.yml new file mode 100644 index 00000000..1879b028 --- /dev/null +++ b/.github/workflows/code-coverage-upload.yml @@ -0,0 +1,31 @@ +name: Upload code coverage + +on: + workflow_run: + workflows: [Build] + types: [completed] + branches: [master] + +jobs: + upload-code-coverage: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + + steps: + - uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.17.x + + - name: Run tests and write coverprofile + shell: bash + run: | + go test -race -coverprofile=profile.out -covermode=atomic ./... + + - name: Upload testcoverage to codecov.io + uses: codecov/codecov-action@v1 + with: + file: ./profile.out + fail_ci_if_error: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..c5c1ea2e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: Publish release + +on: + workflow_run: + workflows: [Build] + types: [completed] + +jobs: + publish-release: + runs-on: ubuntu-latest + # Kinda bad since it might release on any branch starting with v, but it'll do for now. + # Tag filtering in "on:" doesn't work, since the inital build trigger gets lost. + # github.ref is therefore also being reset to "refs/head/master". + if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v') }} + + steps: + - name: Download linux artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: test-and-build.yml + name: scribblers-linux-x64 + + - name: Download macos artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: test-and-build.yml + name: scribblers-macos-x64 + + - name: Download windows artifact + uses: dawidd6/action-download-artifact@v2 + with: + workflow: test-and-build.yml + name: scribblers-x64.exe + + - name: Create release + uses: softprops/action-gh-release@v1 + with: + name: ${{ github.event.workflow_run.head_branch }} + tag_name: ${{ github.event.workflow_run.head_branch }} + files: | + scribblers-linux-x64 + scribblers-macos-x64 + scribblers-x64.exe diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index be6ac8f6..5eb4c624 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -1,105 +1,41 @@ -name: Run tests, build artifacts and upload code coverage +name: Build on: push jobs: - - run-tests: + test-and-build: strategy: matrix: - go-version: [1.16.x] - platform: [ubuntu-latest, macos-latest, windows-latest] + include: + - platform: windows-latest + binary_name: scribblers-x64.exe + - platform: ubuntu-latest + binary_name: scribblers-linux-x64 + - platform: macos-latest + binary_name: scribblers-macos-x64 runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - - name: Run tests and write coverprofile - shell: bash - run: | - go test -race -coverprofile=profile.out -covermode=atomic ./... - - - name: Upload testcoverage to codecov.io - if: github.ref == 'refs/heads/master' && matrix.platform == 'ubuntu-latest' && matrix.go-version == '1.16.x' - uses: codecov/codecov-action@v1 - with: - file: ./profile.out - fail_ci_if_error: true - - # We run builds for the three major platforms on the latest go - # version, while the tests may run on older versions. - - # Each artifact upload has a name specified, so we can avoid uploading - # all artifcats in one zip. - - build-linux: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.16.x - - - name: Build linux artifact - shell: bash - run: | - go build -o scribblers-linux-x64 . - - - name: Upload linux build artifact - uses: actions/upload-artifact@v2 - with: - name: scribblers-linux-x64 - path: ./scribblers-linux-x64 - - build-macos: - runs-on: macos-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.16.x - - - name: Build macos artifact - shell: bash - run: | - go build -o scribblers-macos-x64 . - - - name: Upload macos build artifact - uses: actions/upload-artifact@v2 - with: - name: scribblers-macos-x64 - path: ./scribblers-macos-x64 - - build-windows: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.16.x - - - name: Build windows artifact - shell: cmd - run: | - go build -o scribblers-x64.exe . - - - name: Upload windows build artifact - uses: actions/upload-artifact@v2 - with: - name: scribblers-x64.exe - path: ./scribblers-x64.exe \ No newline at end of file + - uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.17.x + + - name: Run tests + shell: bash + run: | + go test -race -covermode=atomic ./... + + - name: Build artifact + shell: bash + run: | + go build -o ${{ matrix.binary_name }} . + + - name: Upload build artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.binary_name }} + path: ./${{ matrix.binary_name }} diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 31689eca..ecdb1a0e 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -7,7 +7,7 @@ jobs: run-tests: strategy: matrix: - go-version: [1.16.x] + go-version: [1.17.x] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }}