mirror of
https://github.com/Alexandre1a/GoSH.git
synced 2026-03-10 03:29:47 +01:00
109 lines
3.3 KiB
YAML
109 lines
3.3 KiB
YAML
name: Go
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
tags: ["v*"] # Déclenche aussi le workflow quand un tag est poussé
|
|
pull_request:
|
|
branches: ["main"]
|
|
|
|
jobs:
|
|
build-multiarch:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: "1.24.1"
|
|
|
|
- name: Build binaries for multiple architectures
|
|
run: |
|
|
mkdir -p dist
|
|
# Linux
|
|
GOOS=linux GOARCH=amd64 go build -o dist/gosh-linux-amd64
|
|
GOOS=linux GOARCH=arm64 go build -o dist/gosh-linux-arm64
|
|
# macOS
|
|
GOOS=darwin GOARCH=amd64 go build -o dist/gosh-mac-amd64
|
|
GOOS=darwin GOARCH=arm64 go build -o dist/gosh-mac-arm64
|
|
|
|
ls -lh dist/
|
|
|
|
# Windows
|
|
# GOOS=windows GOARCH=amd64 go build -o dist/gosh-windows-amd64.exe
|
|
# GOOS=windows GOARCH=arm64 go build -o dist/gosh-windows-arm64.exe
|
|
|
|
|
|
- name: Upload binaries as artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: gosh-binaries
|
|
path: dist/
|
|
|
|
release:
|
|
needs: build-multiarch
|
|
runs-on: ubuntu-latest
|
|
if: startsWith(github.ref, 'refs/tags/v') # Exécuter uniquement pour les tags commençant par "v"
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download built binaries
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: gosh-binaries
|
|
path: dist/
|
|
|
|
- name: Generate Changelog
|
|
id: changelog
|
|
run: |
|
|
CURRENT_TAG=${GITHUB_REF#refs/tags/}
|
|
# Get all tags sorted by version (descending)
|
|
ALL_TAGS=$(git tag --sort=-version:refname)
|
|
PREVIOUS_TAG=""
|
|
found_current=0
|
|
# Find the tag immediately before the current one
|
|
for tag in $ALL_TAGS; do
|
|
if [ "$found_current" -eq 1 ]; then
|
|
PREVIOUS_TAG=$tag
|
|
break
|
|
fi
|
|
if [ "$tag" == "$CURRENT_TAG" ]; then
|
|
found_current=1
|
|
fi
|
|
done
|
|
# Fallback to initial commit if no previous tag
|
|
if [ -z "$PREVIOUS_TAG" ]; then
|
|
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
|
|
fi
|
|
# Generate changelog
|
|
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG)
|
|
if [ -z "$CHANGELOG" ]; then
|
|
CHANGELOG="No changes since previous release."
|
|
fi
|
|
# Output for GitHub Action
|
|
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
|
|
echo "$CHANGELOG" >> $GITHUB_OUTPUT
|
|
echo "EOF" >> $GITHUB_OUTPUT
|
|
|
|
|
|
- name: Create GitHub Release
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
files: dist/*
|
|
body: |
|
|
**Changelog**
|
|
${{ steps.changelog.outputs.CHANGELOG }}
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
permissions:
|
|
contents: write # Permet de manipuler le contenu du repo
|
|
issues: write # Permet de créer des issues, si nécessaire pour le release
|
|
pull-requests: write # Autorise la gestion des PRs
|
|
actions: write # Permet de gérer les workflows
|
|
pages: write # Si tu utilises GitHub Pages
|
|
discussions: write # Si tu utilises Discussions
|