Simplify + update GHA workflow

This commit is contained in:
John Chadwick 2023-11-15 20:53:19 -05:00 committed by Screwtapello
parent 9560959fef
commit 40486d61c2
1 changed files with 57 additions and 103 deletions

View File

@ -5,6 +5,8 @@ on:
tags: [ 'v*' ] tags: [ 'v*' ]
pull_request: pull_request:
branches: [ master ] branches: [ master ]
permissions:
contents: write
jobs: jobs:
build: build:
strategy: strategy:
@ -18,7 +20,7 @@ jobs:
version: latest version: latest
runs-on: ${{ matrix.os.name }}-${{ matrix.os.version }} runs-on: ${{ matrix.os.name }}-${{ matrix.os.version }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
- name: Install Dependencies - name: Install Dependencies
if: matrix.os.name == 'ubuntu' if: matrix.os.name == 'ubuntu'
run: | run: |
@ -27,22 +29,24 @@ jobs:
- name: Make - name: Make
run: make -j4 -C bsnes local=false run: make -j4 -C bsnes local=false
- name: Upload - name: Upload
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
with: with:
name: bsnes-${{ matrix.os.name }} name: bsnes-${{ matrix.os.name }}
path: bsnes/out/bsnes* path: bsnes/out/bsnes*
release: release:
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
# Prevent multiple conflicting release jobs from running at once.
concurrency: release-${{ github.ref == 'refs/heads/master' && 'nightly' || github.ref }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: needs:
- build - build
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
with: with:
path: 'src' path: 'src'
- name: Download Artifacts - name: Download Artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
path: 'bin' path: 'bin'
- name: Package Artifacts - name: Package Artifacts
@ -83,103 +87,53 @@ jobs:
cd - cd -
done done
- name: Create Release - name: Calculate release info
id: release id: relinfo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
set -eu echo "datetime=$(date -u +"%Y-%m-%d %T %Z")" >> $GITHUB_OUTPUT
github_rest() echo "date=$(date +"%Y-%m-%d")" >> $GITHUB_OUTPUT
{ - name: Delete old nightly release
local method="${1}" uses: actions/github-script@v7
local url="https://api.github.com${2}" id: release
shift 2 if: ${{!startsWith(github.ref, 'refs/tags/')}}
>&2 echo "${method} ${url}" with:
curl \ retries: 3
--fail \ script: |
-H "Accept: application/vnd.github.v3+json" \ const {owner, repo} = context.repo;
-H "Authorization: token ${GITHUB_TOKEN}" \ try {
-X "${method}" \ const release = await github.rest.repos.getReleaseByTag({owner, repo, tag: "nightly"});
"${url}" \ if (release && release.status === 200) {
"$@" await github.rest.repos.deleteRelease({owner, repo, release_id: release.data.id});
} }
github_get_release_id_for_tag() } catch (e) {
{ console.log(`error deleting old release: ${e}`);
payload=$(github_rest GET "/repos/${GITHUB_REPOSITORY}/releases/tags/${1}") || return }
echo "${payload}" | jq .id try {
} await github.rest.git.deleteRef({owner, repo, ref: "tags/nightly"});
github_delete_release_by_id() } catch (e) {
{ console.log(`error trying to delete ref: ${e}`);
github_rest DELETE "/repos/${GITHUB_REPOSITORY}/releases/${1}" }
} await github.rest.git.createTag({
github_delete_tag() owner,
{ repo,
github_rest DELETE "/repos/${GITHUB_REPOSITORY}/git/refs/tags/${1}" tag: "nightly",
} message: "nightly release",
github_create_release() object: context.sha,
{ type: "commit",
local payload="{ })
\"tag_name\": \"${1}\", - name: Create nightly release
\"target_commitish\": \"${2}\", uses: softprops/action-gh-release@v1
\"name\": \"${3}\", if: ${{!startsWith(github.ref, 'refs/tags/')}}
\"body\": \"${4}\", with:
\"draft\": ${5}, tag_name: nightly
\"prerelease\": ${6} name: bsnes nightly ${{steps.relinfo.outputs.date}}
}" body: Auto-generated nightly release on ${{steps.relinfo.outputs.datetime}}
github_rest POST "/repos/${GITHUB_REPOSITORY}/releases" -d "${payload}" files: bsnes*.zip
} prerelease: true
make_nightly_release() - name: Create version release
{ uses: softprops/action-gh-release@v1
github_create_release \ if: ${{startsWith(github.ref, 'refs/tags/')}}
nightly \ with:
"${GITHUB_SHA}" \ name: bsnes ${{github.ref_name}}
"bsnes nightly $(date +"%Y-%m-%d")" \ body: This is bsnes ${{github.ref_name}}, released on ${{steps.relinfo.outputs.date}}.
"Auto-generated nightly release on $(date -u +"%Y-%m-%d %T %Z")" \ files: bsnes*.zip
false \
true
}
make_version_release()
{
github_create_release \
"${1}" \
"${GITHUB_SHA}" \
"bsnes ${1}" \
"This is bsnes ${1}, released on $(date +"%Y-%m-%d")." \
false \
false
}
case ${GITHUB_REF} in
refs/tags/*)
# Create a new version release using the current revision.
echo "UPLOAD_URL=$(make_version_release ${GITHUB_REF#refs/tags/} | jq -r .upload_url)" >> $GITHUB_ENV
;;
refs/heads/master)
# Check for an existing nightly release.
{ release_id=$(github_get_release_id_for_tag nightly); status=$?; } || true
# Delete existing nightly release if it exists.
case ${status} in
0)
github_delete_release_by_id "${release_id}"
# Deleting the 'nightly' release doesn't delete
# the 'nightly' tag, so let's do it manually.
github_delete_tag nightly
;;
22) >&2 echo "No current nightly release; skipping tag deletion." ;;
*) >&2 echo "API call failed unexpectedly." && exit 1 ;;
esac
# Create a new nightly release using the current revision.
echo "UPLOAD_URL=$(make_nightly_release | jq -r .upload_url)" >> $GITHUB_ENV
;;
esac
- name: Upload bsnes-ubuntu
uses: actions/upload-release-asset@v1
env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }
with: { upload_url: '${{ env.UPLOAD_URL }}', asset_path: 'bsnes-ubuntu.zip', asset_name: 'bsnes-ubuntu.zip', asset_content_type: 'application/zip' }
- name: Upload bsnes-windows
uses: actions/upload-release-asset@v1
env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }
with: { upload_url: '${{ env.UPLOAD_URL }}', asset_path: 'bsnes-windows.zip', asset_name: 'bsnes-windows.zip', asset_content_type: 'application/zip' }
- name: Upload bsnes-macos
uses: actions/upload-release-asset@v1
env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }
with: { upload_url: '${{ env.UPLOAD_URL }}', asset_path: 'bsnes-macos.zip', asset_name: 'bsnes-macos.zip', asset_content_type: 'application/zip' }