Skip to content

fix maybe?

fix maybe? #5

Workflow file for this run

name: Build, Test and Release
on:
push:
branches: [ "main", "master" ]
tags: [ "v*" ]
pull_request:
branches: [ "main", "master" ]
env:
GO_VERSION: '1.24.2'
jobs:
# Test job that runs on multiple platforms
test:
name: Test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
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: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Run go fmt
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "Code is not formatted properly:"
gofmt -s -d .
exit 1
fi
shell: bash
- name: Run go vet
run: go vet ./...
- name: Run staticcheck
uses: dominikh/[email protected]
with:
version: "2024.1.1"
install-go: false
- name: Run tests
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
fail_ci_if_error: false
- name: Test build
run: go build -v ./...
# Build job for multiple platforms (only on tags)
build:
name: Build
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: linux
goarch: 386
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
- goos: windows
goarch: 386
- goos: freebsd
goarch: amd64
- goos: openbsd
goarch: amd64
- goos: netbsd
goarch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Get version and commit info
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
COMMIT=$(git rev-parse --short HEAD)
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "COMMIT=${COMMIT}" >> $GITHUB_OUTPUT
echo "BUILD_TIME=${BUILD_TIME}" >> $GITHUB_OUTPUT
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
BINARY_NAME="gomail"
ARCHIVE_NAME="gomail-${{ steps.version.outputs.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
# Build with version information
go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.VERSION }} -X main.commit=${{ steps.version.outputs.COMMIT }} -X main.buildTime=${{ steps.version.outputs.BUILD_TIME }}" -o "${BINARY_NAME}"
# Create archive
mkdir -p dist
if [ "${{ matrix.goos }}" = "windows" ]; then
zip "dist/${ARCHIVE_NAME}.zip" "${BINARY_NAME}" README.md LICENSE 2>/dev/null || zip "dist/${ARCHIVE_NAME}.zip" "${BINARY_NAME}" README.md || zip "dist/${ARCHIVE_NAME}.zip" "${BINARY_NAME}"
else
tar -czf "dist/${ARCHIVE_NAME}.tar.gz" "${BINARY_NAME}" README.md LICENSE 2>/dev/null || tar -czf "dist/${ARCHIVE_NAME}.tar.gz" "${BINARY_NAME}" README.md || tar -czf "dist/${ARCHIVE_NAME}.tar.gz" "${BINARY_NAME}"
fi
# Generate checksums
cd dist
if [ "${{ matrix.goos }}" = "windows" ]; then
sha256sum "${ARCHIVE_NAME}.zip" > "${ARCHIVE_NAME}.zip.sha256"
else
sha256sum "${ARCHIVE_NAME}.tar.gz" > "${ARCHIVE_NAME}.tar.gz.sha256"
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: gomail-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/*
retention-days: 7
# Release job
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
discussions: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: gomail-*
- name: Organize artifacts
run: |
mkdir -p release
find artifacts -name "*.zip" -o -name "*.tar.gz" -o -name "*.sha256" | xargs -I {} cp {} release/
ls -la release/
- name: Generate changelog
id: changelog
run: |
if [ -f CHANGELOG.md ]; then
# Extract changelog for current version
awk "/^## \[?${VERSION}\]?/,/^## \[?[0-9]/" CHANGELOG.md | head -n -1 | tail -n +2 > current_changelog.md
else
# Generate basic changelog from git commits
echo "## Changes" > current_changelog.md
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD~1)..HEAD >> current_changelog.md 2>/dev/null || echo "- Initial release" >> current_changelog.md
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
cat current_changelog.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.VERSION }}
name: "Release ${{ steps.version.outputs.VERSION }}"
body: |
${{ steps.changelog.outputs.CHANGELOG }}
## Installation
Download the appropriate binary for your platform from the assets below.
### Quick Install (Linux/macOS)
```bash
# Replace with your platform
curl -L https://github.com/${{ github.repository }}/releases/download/${{ steps.version.outputs.VERSION }}/gomail-${{ steps.version.outputs.VERSION }}-linux-amd64.tar.gz | tar xz
```
## Checksums
All binaries include SHA256 checksums for verification.
files: release/*
draft: false
prerelease: ${{ contains(steps.version.outputs.VERSION, '-') }}
generate_release_notes: true
discussion_category_name: "Announcements"