release in archives, for proper naming of binaries without version an… #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
# Check out | |
- uses: actions/checkout@v4 | |
# Extract version information | |
- name: Extract project version | |
id: project_version | |
run: echo "version=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)" >> $GITHUB_OUTPUT | |
- name: Extract commit hash | |
id: git_commit | |
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
# Prepare build | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.21.x | |
- name: Download dependencies | |
run: go mod tidy | |
# Build Linux | |
- name: Build Linux | |
run: | | |
env GOOS=linux GOARCH=amd64 go build -o colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp.go | |
mv -f colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp | |
chmod a+x colorexp | |
tar -czvf colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz colorexp | |
- name: Upload Linux artifact | |
if: github.event_name == 'push' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz | |
path: colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz | |
# Build Darwin | |
- name: Build Darwin | |
run: | | |
env GOOS=darwin GOARCH=amd64 go build -o colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp.go | |
mv -f colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp | |
chmod a+x colorexp | |
tar -czvf colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz colorexp | |
- name: Upload Darwin artifact | |
if: github.event_name == 'push' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} | |
path: colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} | |
# Build Windows | |
- name: Build Windows | |
run: | | |
env GOOS=windows GOARCH=amd64 go build -o colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp.go | |
mv -f colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp.exe | |
zip colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip colorexp.exe | |
- name: Upload Windows artifact | |
if: github.event_name == 'push' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip | |
path: colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip | |
# Create a GitHub release | |
- name: Create Release | |
id: create_release | |
if: github.event_name == 'push' | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.project_version.outputs.version }} | |
release_name: Release ${{ steps.project_version.outputs.version }} | |
draft: false | |
prerelease: false | |
# Upload release asset for Linux | |
- name: Upload Release Asset Linux | |
if: github.event_name == 'push' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz | |
asset_name: colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz | |
asset_content_type: application/octet-stream | |
# Upload release asset for Darwin | |
- name: Upload Release Asset Darwin | |
if: github.event_name == 'push' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz | |
asset_name: colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz | |
asset_content_type: application/octet-stream | |
# Upload release asset for Windows | |
- name: Upload Release Asset Windows | |
if: github.event_name == 'push' | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip | |
asset_name: colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip | |
asset_content_type: application/octet-stream |