archives #4
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 and Release | |
on: | |
push: | |
branches: | |
- "*" | |
tags: | |
- "v*" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get branch name | |
id: branch | |
run: echo "::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/})" | |
shell: bash | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.21.3 | |
- name: Build Binaries | |
id: build | |
env: | |
LINUX_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-linux-amd64.tar.gz | |
LINUX_ARM_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-linux-arm.tar.gz | |
WIN_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-win-amd64.zip | |
run: | | |
echo "Building Linux amd64 binary" | |
GOOS=linux GOARCH=amd64 go build -o na | |
tar -czvf ${LINUX_AMD_ARCHIVE} na | |
rm -v na | |
echo "Building Linux ARM binary" | |
GOOS=linux GOARCH=arm go build -o na | |
tar -czvf ${LINUX_ARM_ARCHIVE} na | |
rm -v na | |
echo "Building Windows amd64 binary" | |
GOOS=windows GOARCH=amd64 go build -o na.exe | |
zip ${WIN_AMD_ARCHIVE} na.exe | |
rm -v na.exe | |
ls -lah | |
- name: Upload binaries to artifacts (feature branch only) | |
if: contains(github.ref, 'refs/heads/') | |
uses: actions/upload-artifact@v2 | |
env: | |
LINUX_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-linux-amd64.tar.gz | |
LINUX_ARM_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-linux-arm.tar.gz | |
WIN_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-win-amd64.zip | |
with: | |
name: binaries | |
path: | | |
${LINUX_AMD_ARCHIVE} | |
${LINUX_ARM_ARCHIVE} | |
${WIN_AMD_ARCHIVE} | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get branch name | |
id: branch | |
run: echo "::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/})" | |
shell: bash | |
- name: Download binaries from artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: binaries | |
- name: Create Release | |
id: create_release | |
uses: gh-actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Sodium ${{ github.ref }} | |
draft: false | |
prerelease: false | |
- name: Upload Linux amd64 Archive | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
LINUX_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-linux-amd64.tar.gz | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./${LINUX_AMD_ARCHIVE} | |
asset_name: ${LINUX_AMD_ARCHIVE} | |
asset_content_type: application/octet-stream | |
- name: Upload Linux ARM Archive | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
LINUX_ARM_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-linux-arm.tar.gz | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./${LINUX_ARM_ARCHIVE} | |
asset_name: ${LINUX_ARM_ARCHIVE} | |
asset_content_type: application/octet-stream | |
- name: Upload Windows amd64 Archive | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WIN_AMD_ARCHIVE: sodium-${{ steps.branch.outputs.branch }}-win-amd64.zip | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./${WIN_AMD_ARCHIVE} | |
asset_name: ${WIN_AMD_ARCHIVE} | |
asset_content_type: application/octet-stream |