Skip to content

test: make version test more generic #145

test: make version test more generic

test: make version test more generic #145

Workflow file for this run

# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Build & Tests
on:
push:
paths-ignore:
- 'README.md'
- 'CONTRIBUTING.md'
branches:
- main
- feature/*
- bugfix/*
pull_request:
branches:
- main
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, windows, darwin]
arch: [amd64, arm64]
exclude:
- os: windows
arch: arm64 # Windows ARM64 is not supported by Go
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup GoLang
uses: actions/setup-go@v5
with:
go-version: '~1.23.4'
# - name: Run vet & lint
# run: |
# go install golang.org/x/lint/golint@latest
# go vet cmd
# golint cmd
# - uses: actions/setup-python@v5
# - uses: pre-commit/[email protected]
- name: Get Version from Tag
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Build
id: build
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
run: |
set -x
go version
export CGO_ENABLED=0
OUTPUT_NAME=td-${{ matrix.os }}-${{ matrix.arch }}
if [ "${{ matrix.os }}" == "windows" ]; then
OUTPUT_NAME+=".exe"
fi
if [ "${{ matrix.os }}" == "darwin" ]; then
OUTPUT_NAME=td-macos-${{ matrix.arch }}
fi
go build \
-ldflags="-X main.BuildVersion=${VERSION}" \
-o bin/$OUTPUT_NAME \
./cmd/td
echo "binary=${OUTPUT_NAME}" >> "$GITHUB_OUTPUT"
- name: Run UPX
uses: crazy-max/ghaction-upx@v3
# macos is not supported
if: ${{ matrix.os != 'darwin' }}
with:
version: latest
files: |
./bin/*
args: -fq
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.binary }}
path: bin/*
unit-tests:
name: run unit tests
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup GoLang
uses: actions/setup-go@v5
with:
go-version: '~1.23.4'
- uses: actions/download-artifact@v4
with:
name: td-linux-amd64
path: ./bin
- name: Run Unit Tests
run: |
mv ./bin/td-linux-amd64 ./bin/td
chmod +x ./bin/td
go test -v ./...
smoke-tests:
name: smoke test on ${{ matrix.os }}
needs:
- build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
binary: td-linux-amd64
- os: macos-latest
binary: td-macos-amd64
- os: windows-latest
binary: td-windows-amd64.exe
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: ${{ matrix.binary }}
path: .
- name: Get Version from Tag
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Run test on Linux/MacOS
if: matrix.os != 'windows-latest'
run: |
chmod +x ${{ matrix.binary }}
./${{ matrix.binary }} -V
./${{ matrix.binary }} --config tests/test-1.yaml --tag ${VERSION} --delete
./${{ matrix.binary }} --config tests/test-2.yaml --tag ${VERSION} --delete
./${{ matrix.binary }} --config tests/test-4.yaml --tag ${VERSION} --delete
./${{ matrix.binary }} --config tests/test-5.yaml --tag ${VERSION} --delete
./${{ matrix.binary }} --config tests/test-7.yaml --tag ${VERSION} --delete
- name: Run test on Windows
if: matrix.os == 'windows-latest'
shell: cmd
run: |
.\\${{ matrix.binary }} -V
.\\${{ matrix.binary }} --config tests/test-1.yaml --tag ${VERSION} --delete
.\\${{ matrix.binary }} --config tests/test-2.yaml --tag ${VERSION} --delete
.\\${{ matrix.binary }} --config tests/test-4.yaml --tag ${VERSION} --delete
.\\${{ matrix.binary }} --config tests/test-5.yaml --tag ${VERSION} --delete
.\\${{ matrix.binary }} --config tests/test-7.yaml --tag ${VERSION} --delete
release:
permissions: write-all
runs-on: ubuntu-latest
needs:
- unit-tests
- smoke-tests
- build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from tag on master
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/download-artifact@v4
with:
# download all
path: bin
merge-multiple: true
- name: Calculate checksums
run: |
cd bin
sha512sum td-* > sha512sums.txt
- name: Bump version and push tag
if: github.ref == 'refs/heads/main'
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create normal GitHub release
if: github.ref == 'refs/heads/main' && github.event_name != 'schedule'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
- name: Upload multiple assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
for asset in bin/*; do
gh release upload "${{ steps.tag_version.outputs.new_tag }}" "$asset"
done