Skip to content

Add main application entry point and update .gitignore for binary exc… #1

Add main application entry point and update .gitignore for binary exc…

Add main application entry point and update .gitignore for binary exc… #1

Workflow file for this run

name: Release Go Binaries
# Trigger workflow only when a tag is pushed that matches the pattern v*
on:
push:
tags:
- 'v*'
permissions:
contents: write # Required for creating releases
jobs:
build:
name: Build Binaries
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21.x']
platform:
- { os: linux, arch: amd64 }
- { os: linux, arch: arm64 }
- { os: windows, arch: amd64 }
- { os: darwin, arch: amd64 }
- { os: darwin, arch: arm64 }
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Build
env:
GOOS: ${{ matrix.platform.os }}
GOARCH: ${{ matrix.platform.arch }}
CGO_ENABLED: 0 # Disable CGO for static binaries
run: |
BINARY_NAME="dir-dumper"
if [ "${{ matrix.platform.os }}" = "windows" ]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
OUTPUT_PATH="./dist/${BINARY_NAME}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}"
# Build with optimization flags
go build -trimpath -ldflags="-s -w" -o $OUTPUT_PATH ./cmd/dir-dumper/
shell: bash
- name: Create Archive
run: |
BINARY_NAME="dir-dumper"
ARCHIVE_BASE_NAME="${BINARY_NAME}-${{ github.ref_name }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}"
SOURCE_BINARY="./dist/${BINARY_NAME}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}"
# Create different archive types based on target OS
if [ "${{ matrix.platform.os }}" = "windows" ]; then
SOURCE_BINARY="${SOURCE_BINARY}.exe"
7z a "./dist/${ARCHIVE_BASE_NAME}.zip" "${SOURCE_BINARY}" README.md
else
tar -czvf "./dist/${ARCHIVE_BASE_NAME}.tar.gz" -C ./dist "${SOURCE_BINARY##*/}" README.md
fi
shell: bash
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: dir-dumper-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
path: ./dist/*.tar.gz
if-no-files-found: error
- name: Upload Windows Artifact
if: matrix.platform.os == 'windows'
uses: actions/upload-artifact@v4
with:
name: dir-dumper-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
path: ./dist/*.zip
if-no-files-found: error
release:
name: Create Release
needs: build # Wait for build job to complete
runs-on: ubuntu-latest
permissions:
contents: write # Required for release creation
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ./dist/artifacts
- name: Generate Checksums
run: |
cd ./dist/artifacts
# Move all artifacts to the root artifacts directory
find . -mindepth 2 -type f -exec mv -i '{}' . \;
# Generate SHA256 checksums for all artifacts
sha256sum * > checksums.txt
mv checksums.txt ..
cd ../..
shell: bash
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
generate_release_notes: true
make_latest: true
files: |
./dist/artifacts/*
./dist/checksums.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}