My "fetch info" workflow took around 3minutes 26 seconds to complete this morning. It installs nix, gets a shell with cargo
and rustc
, and then executes cargo run
.
I created another workflow to download rustup
, run cargo build --release
, and to output an artifact:
- name: build netplay-bracket-finder
run: |
cd rust && cargo build --release
- name: upload artifact
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3
with:
name: netplay-bracket-finder-x86_64-linux
path: rust/target/release/netplay-bracket-finder
I modified my fetch workflow to use the gh
CLI to grab the latest released binary when fetching info:
- name: fetch info from api
run: |
# download latest binary from release
gh release download --pattern 'netplay-bracket-finder'
chmod +x ./netplay-bracket-finder
stat ./netplay-bracket-finder
# fetch info from API
./netplay-bracket-finder | tee docs/events.json
env:
GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
And finally I made a release workflow that downloads the artifact from a successful build, creates a tag, and then creates a release using the gh
CLI:
on:
workflow_dispatch:
inputs:
tag:
description: 'tag for release'
required: true
type: string
id:
description: 'id of build'
required: true
type: string
# find commit of workflow build
SHA="$(gh run view ${{ inputs.id }} --json headSha -q '.headSha')"
if [[ -z $SHA ]]; then exit 1; fi
# download artifact from workflow build
gh run download "${{ inputs.id }}" -p 'netplay-bracket-finder-x86_64-linux'
# create and push tag for commit
git tag "${{ inputs.tag }}" "${SHA}" && git push --tags
# create release with tag + artifact
gh release create "${{ inputs.tag }}" \
'./netplay-bracket-finder-x86_64-linux/netplay-bracket-finder#x86_64-linux'
Now I can create releases from successful CI builds easily, and my "fetch info" workflow takes only 13 seconds! gh run list
is very cool.
I ran into issues halfway through - the rust binaries I built with nix did not run after I downloaded the artifacts! They were dynamically linked to object files in /nix/store
, and the new agents didn't have /nix/store
. I tried build a statically linked rust binary with nix for a while, but I had issues linking, and didn't want to keep exploring.