Skip to content

minor updates

minor updates #5

name: Build, Release, and Publish
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
GO_VERSION: '1.22'
BINARY_NAME: 'ingest'
permissions:
contents: write
packages: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: darwin
arch: arm64
- os: linux
arch: amd64
- os: linux
arch: arm64
outputs:
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-go-
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Get dependencies
run: go mod download
- name: Run tests
run: go test -v ./...
- name: Build
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
run: go build -v -ldflags "-X main.Version=$VERSION" -o ${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }} .
- name: Upload artifact
uses: actions/upload-artifact@v4
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
path: build/${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
retention-days: 90
release:
name: Release
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: |
ingest-linux-amd64
ingest-linux-arm64
ingest-darwin-arm64
path: build/
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
artifacts: build/
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.build.outputs.VERSION }}
# - name: Update latest tag
# run: |
# git config user.name github-actions
# git config user.email [email protected]
# git tag -f latest
# git push origin latest --force