Skip to content

fix DFanso#121 : add systematic logging for store operations #176

fix DFanso#121 : add systematic logging for store operations

fix DFanso#121 : add systematic logging for store operations #176

name: Build and Release
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
jobs:
auto-tag:
name: Auto Tag
runs-on: ubuntu-latest
# Only run on main branch pushes, not on tag pushes or PRs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
tag_created: ${{ steps.tag_version.outputs.new_tag != '' }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Auto Tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: patch
create_annotated_tag: true
tag_prefix: v
- name: Print Tag Info
run: |
echo "New tag: ${{ steps.tag_version.outputs.new_tag }}"
echo "Tag created: ${{ steps.tag_version.outputs.new_tag != '' }}"
test:
name: Test
permissions:
contents: read
runs-on: ubuntu-latest
needs: auto-tag
# Always run tests, even if auto-tag was skipped
if: always() && (needs.auto-tag.result == 'success' || needs.auto-tag.result == 'skipped')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23' # Use the appropriate Go version for your project
- name: Get dependencies
run: go mod download
- name: Auto-format code
run: |
# Auto-format all Go files
gofmt -s -w .
# Check if any files were formatted
if [ -n "$(git status --porcelain 2>/dev/null)" ]; then
echo "Some files were auto-formatted in the build process."
git diff --name-only
fi
- name: Run tests
run: go test -v ./...
build:
name: Build Go Binary
permissions:
contents: read
runs-on: ${{ matrix.os }}
needs: [auto-tag, test]
# Only build if tests passed
if: always() && (needs.auto-tag.result == 'success' || needs.auto-tag.result == 'skipped') && needs.test.result == 'success'
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
artifact_name: commit
asset_name: commit-linux-amd64
- os: windows-latest
artifact_name: commit.exe
asset_name: commit-windows-amd64.exe
- os: macos-latest
artifact_name: commit
asset_name: commit-macos-amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23' # Use the appropriate Go version for your project
- name: Get dependencies
run: go mod download
- name: Build
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
go build -v -o ${{ matrix.artifact_name }} -ldflags="-s -w" ./cmd/commit-msg
else
go build -v -o ${{ matrix.artifact_name }} -ldflags="-s -w" ./cmd/commit-msg
fi
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.artifact_name }}
package:
name: Package Binaries
permissions:
contents: read
needs: [auto-tag, build]
runs-on: ubuntu-latest
# Always run after build
if: always() && needs.build.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Linux Binary
uses: actions/download-artifact@v4
with:
name: commit-linux-amd64
path: ./binaries/linux
- name: Download Windows Binary
uses: actions/download-artifact@v4
with:
name: commit-windows-amd64.exe
path: ./binaries/windows
- name: Download macOS Binary
uses: actions/download-artifact@v4
with:
name: commit-macos-amd64
path: ./binaries/macos
- name: Show downloaded files
run: |
find ./binaries -type f
- name: Make binaries executable
run: |
chmod +x ./binaries/linux/commit
chmod +x ./binaries/macos/commit
- name: Create packages
run: |
mkdir -p ./packages
# Package Linux binary
tar -C ./binaries/linux -czf ./packages/commit-linux-amd64.tar.gz commit
# Package Windows binary
zip -j ./packages/commit-windows-amd64.zip ./binaries/windows/commit.exe
# Package macOS binary
tar -C ./binaries/macos -czf ./packages/commit-macos-amd64.tar.gz commit
# List created packages
ls -la ./packages/
- name: Upload packages as artifacts
uses: actions/upload-artifact@v4
with:
name: release-packages
path: ./packages/*
release:
name: Create Release
needs: [auto-tag, build, package]
# Run if a tag was created by auto-tag or this is a tag push
if: (needs.auto-tag.outputs.new_tag != '') || (github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download packages
uses: actions/download-artifact@v4
with:
name: release-packages
path: ./packages
- name: List package files
run: |
ls -la ./packages/
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.auto-tag.outputs.new_tag != '' && needs.auto-tag.outputs.new_tag || github.ref_name }}
name: Release ${{ needs.auto-tag.outputs.new_tag != '' && needs.auto-tag.outputs.new_tag || github.ref_name }}
files: |
./packages/commit-linux-amd64.tar.gz
./packages/commit-windows-amd64.zip
./packages/commit-macos-amd64.tar.gz
draft: false
prerelease: false
generate_release_notes: true