Skip to content

fix: workflow

fix: workflow #15

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21.5
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build binaries
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Check if release exists
id: check_release
run: |
TAG_NAME=${{ github.ref }} # refs/tags/v0.1.0
TAG_NAME=${TAG_NAME#refs/tags/} # v0.1.0
RELEASE_ID=$(curl --silent --show-error --header "Authorization: token ${{ secrets.PAT }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME" | jq '.id')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
if: env.RELEASE_ID == 'null'
- name: Upload Release Assets
run: |
UPLOAD_URL=$(if [ "${{ env.RELEASE_ID }}" == "null" ]; then echo "${{ steps.create_release.outputs.upload_url }}"; else echo "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets"; fi)
for file in dist/*; do
if [[ -f "$file" ]]; then
filename=$(basename -- "$file")
extension="${filename##*.}"
if [[ "$extension" == "exe" || "$extension" == "tar.gz" ]]; then
echo "Uploading $file"
curl \
--header "Authorization: token ${{ secrets.PAT }}" \
--header "Content-Type: $(file -b --mime-type $file)" \
--data-binary @"$file" \
"$UPLOAD_URL?name=$(basename $file)"
fi
fi
done