Skip to content

Merge pull request #3 from tgagor/dependabot/go_modules/github.com/ma… #216

Merge pull request #3 from tgagor/dependabot/go_modules/github.com/ma…

Merge pull request #3 from tgagor/dependabot/go_modules/github.com/ma… #216

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
- name: Guess next version
id: guessed_tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: true
append_to_pre_release_tag: pre
- name: Extract version from tag
env:
VERSION_TAG: ${{ steps.guessed_tag_version.outputs.new_tag }}
run: echo "VERSION=$(echo $VERSION_TAG | sed -e "s/^v//" -e "s/-.*$//")" >> $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/*
pre-commit:
name: pre-commit checks
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'
- id: vars
run: |
echo "GOBIN=$(go env GOPATH)/bin" >> "$GITHUB_OUTPUT"
- name: Restore cached linting tools
uses: actions/cache/restore@v4
with:
path: |
${{ steps.vars.outputs.GOBIN }}/goimports
${{ steps.vars.outputs.GOBIN }}/gocyclo
${{ steps.vars.outputs.GOBIN }}/golangci-lint
${{ steps.vars.outputs.GOBIN }}/gocritic
key: golint-v1-${{ github.job }}-${{ runner.os }}-${{ steps.vars.outputs.GOVERSION }}-${{ hashFiles('Makefile') }}
- name: Install dependencies
run: |
make install-linters
- name: Update cache of linting tools
uses: actions/cache/save@v4
with:
path: |
${{ steps.vars.outputs.GOBIN }}/goimports
${{ steps.vars.outputs.GOBIN }}/gocyclo
${{ steps.vars.outputs.GOBIN }}/golangci-lint
${{ steps.vars.outputs.GOBIN }}/gocritic
key: golint-v1-${{ github.job }}-${{ runner.os }}-${{ steps.vars.outputs.GOVERSION }}-${{ hashFiles('Makefile') }}
- uses: pre-commit/[email protected]
unit-tests:
name: unit tests
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'
- name: Run Unit Tests
run: |
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
./${{ matrix.binary }} --config tests/test-9.yaml --tag ${VERSION} --delete
./${{ matrix.binary }} --config tests/test-10.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
.\\${{ matrix.binary }} --config tests/test-9.yaml --tag ${VERSION} --delete
.\\${{ matrix.binary }} --config tests/test-10.yaml --tag ${VERSION} --delete
release:
permissions: write-all
runs-on: ubuntu-latest
needs:
- pre-commit
- 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
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