Checkout fetch-depth:0 so version stamping can find the latest tag #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
with: | |
fetch-tags: true | |
- 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 | |
with: | |
fetch-tags: true | |
- 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/** | |
if-no-files-found: error | |
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 |