Skip to content

Build and release Go Project #7

Build and release Go Project

Build and release Go Project #7

Workflow file for this run

# .github/workflows/release.yaml
name: Build and release Go Project
on:
release:
types: [created]
jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
permissions: write-all
strategy:
matrix:
# List of GOOS and GOARCH pairs from `go tool dist list`
goosarch:
- 'linux/ppc64le'
- 'linux/amd64'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v5 # Recommended action to set up Go environment
with:
go-version-file: 'go.mod' # Automatically detects the Go version from go.mod
- name: Get OS and arch info
run: |
GOOSARCH=${{matrix.goosarch}}
GOOS=${GOOSARCH%/*}
GOARCH=${GOOSARCH#*/}
REPO=${{github.repository}}
BINARY_NAME=${REPO#*/}-$GOOS-$GOARCH
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_ENV
echo "GOOS=$GOOS" >> $GITHUB_ENV
echo "GOARCH=$GOARCH" >> $GITHUB_ENV
- name: Set version variable
run: echo "PROGRAM_VERSION="$(git describe --always --long --dirty) >> ${GITHUB_ENV}
- name: Set release variable
run: echo "PROGRAM_RELEASE="$(git describe --tags --abbrev=0) >> ${GITHUB_ENV}
- name: Build project
run: go build -ldflags="-X main.version=$(git describe --always --long --dirty) -X main.release=$(git describe --tags --abbrev=0)" -o "$BINARY_NAME" *.go
- name: Release binaries
uses: softprops/action-gh-release@v1
# https://github.com/softprops/action-gh-release
with:
files: |
${{ env.BINARY_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided secret
- name: Release scripts
uses: softprops/action-gh-release@v1
# https://github.com/softprops/action-gh-release
if: ${{ env.GOARCH }} == 'amd64'

Check warning on line 61 in .github/workflows/release.yml

View workflow run for this annotation

GitHub Actions / Build and release Go Project

Workflow syntax warning

.github/workflows/release.yml (Line: 61, Col: 11): Conditional expression contains literal text outside replacement tokens. This will cause the expression to always evaluate to truthy. Did you mean to put the entire expression inside ${{ }}?
with:
files: |
scripts/create-cluster.sh
scripts/delete-cluster.sh
scripts/console.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided secret