Skip to content

Commit

Permalink
Split and retool build workflow into CI and Release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
flwyd committed Feb 3, 2024
1 parent 560dd80 commit 3a3c9fc
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 40 deletions.
69 changes: 29 additions & 40 deletions .github/workflows/go-build.yml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,80 +12,69 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: Go
# This workflow performs continuous integration testing: run unit tests and
# ensure adifmt builds under all target platforms on each branch push or pull
# request. Uploads build artifacts but does not create a release.
name: Build and test

env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_LOG: true

on:
push:
branches: ["main"]
tags: ["v[0-9]+.*"]
branches:
- '*'
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'

# Uses Go version declared in go.mod to ensure we don't introduce API calls to
# newer standard library functions.
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ">=1.18"
go-version-file: go.mod
cache: true

- name: Test
run: go test ./...

build:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm64]
goarch: ['386', amd64, arm64]
exclude:
- goarch: "386"
- goarch: '386'
goos: darwin
include:
- goarch: arm
goos: linux

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
- uses: actions/setup-go@v4
with:
go-version: ">=1.18"
go-version-file: go.mod
cache: true

- name: Build ${{ matrix.goos }} ${{ matrix.goarch }}
run: go build -v -o adifmt-${{ matrix.goos }}-${{ matrix.goarch }} ./adifmt
run: |
go build -v -trimpath \
-o build/adif-multitool-${{ matrix.goos }}-${{ matrix.goarch }}/ \
-ldflags "-X 'main.version=$(git describe --dirty --match='v[0-9]*')'" \
./adifmt
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}

- name: Upload artifact
uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v3
with:
name: adifmt-builds
path: adifmt-${{ matrix.goos }}-${{ matrix.goarch }}

release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: adifmt-builds

- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: false
title: "Latest Build"
files: |
adifmt-*
path: build/**
91 changes: 91 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This workflow creates a release and builds adifmt binaries for several
# platforms whenever a new version tag (v1.2.3) is pushed.
name: Create Release

env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_LOG: true

on:
push:
tags:
- v[0-9]+.*

# Builds with the latest Go, regardless of version declared by go.mod, so we
# pick up compiler improvements. CI builds with specified version to avoid API
# usage regressions.
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '>=1.18'
cache: true
- name: Test
run: go test ./...

build:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: ['386', amd64, arm64]
exclude:
- goarch: '386'
goos: darwin
include:
- goarch: arm
goos: linux

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '>=1.18'
cache: true
- name: Build ${{ matrix.goos }} ${{ matrix.goarch }}
run: |
go build -v -trimpath \
-o build/adifmt-${{ matrix.goos }}-${{ matrix.goarch }}/ \
-ldflags "-X 'main.version=${{ github.ref_name }}'" \
./adifmt
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
- uses: actions/upload-artifact@v4
with:
name: adifmt-builds
path: build/**

release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: adifmt-builds
- name: Create release ${{ github.ref_name }}
uses: softprops/action-gh-release@v1
with:
files: adifmt-builds/*
fail_on_unmatched_files: true
generate_release_notes: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*.so
*.dylib

# Build output directory
build/

# Test binary, built with `go test -c`
*.test

Expand Down

0 comments on commit 3a3c9fc

Please sign in to comment.