Skip to content

Add GitHub action (#22) #5

Add GitHub action (#22)

Add GitHub action (#22) #5

Workflow file for this run

name: Go CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.22'
- name: Run static checks
run: go vet ./...
- name: Run audit
run: go mod tidy && go mod vendor
- name: Format code
run: go fmt ./...
- name: Test
run: go test -v ./...
- name: Build
run: go build -o tgcom ./cmd/tgcom
- name: Semantic Versioning
id: semver
run: |
VERSION=$(git describe --tags --abbrev=0)
if [ -z "$VERSION" ]; then
VERSION="v0.1.0"
else
VERSION=$(echo "$VERSION" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
fi
echo "New version: $VERSION"
echo "::set-output name=version::$VERSION"
release:
needs: build
name: Release
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Create release
uses: actions/create-release@v1
with:
tag_name: ${{ needs.build.outputs.semver }}
release_name: ${{ needs.build.outputs.semver }}
body: |
Release ${{ needs.build.outputs.semver }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}