Skip to content

Commit

Permalink
Improve build workflows
Browse files Browse the repository at this point in the history
* Use go 1.17.x
* Separate build steps into different files
* Add new build steps to publish a release upon a new tag
  • Loading branch information
Bios-Marcel committed Feb 19, 2022
1 parent df9f887 commit 734114c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 96 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/code-coverage-upload.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
126 changes: 31 additions & 95 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
@@ -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
- 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 }}
2 changes: 1 addition & 1 deletion .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 734114c

Please sign in to comment.