Create a Release and Push Release assets #4
Workflow file for this run
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: Create a Release and Push Release assets | |
on: | |
create: | |
tags: '*' | |
workflow_dispatch: | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create-release.outputs.upload_url }} | |
steps: | |
- name: Check if release exists | |
id: check-release | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
try { | |
const response = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: "${{ github.ref_name }}" | |
}); | |
if (response.status === 200) { | |
console.log(`Release with tag exists.`); | |
core.setOutput('release-exists', 'true'); | |
} | |
} catch (error) { | |
if (error.status === 404) { | |
console.log(`Release with tag does not exist.`); | |
core.setOutput('release-exists', 'false'); | |
} else { | |
throw error; | |
} | |
} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/create-release@v1 | |
if: ${{ steps.check-release.outputs.release-exists == 'false'}} | |
id: create-release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: ${{ github.ref_name }} | |
draft: true | |
prerelease: true | |
build-artifacts: | |
needs: | |
- create-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22.5" | |
- name: Install Dependencies | |
run: | | |
go install "github.com/goreleaser/nfpm/v2/cmd/nfpm@latest" | |
- name: Build Packages | |
env: | |
PAT: ${{ secrets.PAT }} | |
run: | | |
git config --global url."https://${PAT}:[email protected]/".insteadOf "https://github.com/" | |
make packages | |
- name: Find files matching "*.rpm" "*.deb" and "*sha256" | |
run: | | |
ASSET_LIST=$(find . -type f \( -name "*.deb" -or -name "*.rpm" -or -name "*.sha256" \) | tr '\n' ',') | |
echo "ASSET_LIST=$ASSET_LIST" >> $GITHUB_ENV | |
- name: Upload Assets | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
upload_url="$(echo "${{ needs.create-release.outputs.upload_url }}" | sed 's/\(assets\).*/\1/')" | |
IFS=',' read -r -a asset_array <<< "$ASSET_LIST" | |
for file in "${asset_array[@]}"; do | |
curl -L \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
-H "Content-Type: $(file -b --mime-type $file)" \ | |
"$upload_url?name=$(basename $file)" \ | |
--data-binary "@$file" | |
done |