ci(loader): add workflow dispatch to publish loader and refine CI steps #10
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: π¨βπ» Test & Deploy AO CLI | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "dev-cli/**" | |
push: | |
branches: | |
- main | |
paths: | |
- "dev-cli/**" | |
# Perform a release using a workflow dispatch | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "semver version to bump to" | |
required: true | |
defaults: | |
run: | |
shell: bash | |
working-directory: dev-cli | |
jobs: | |
# Run only run tests on PRs and pushes to main | |
test: | |
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
deno-version: [1.x] | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v3 | |
- name: π¦ Setup Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: ${{ matrix.deno-version }} | |
- name: β‘ Run Tests | |
run: | | |
deno task test | |
env: | |
CI: true | |
test-publish-command: | |
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v3 | |
- name: β Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: β‘ Run Tests | |
working-directory: dev-cli/container/src/publish | |
run: | | |
npm i | |
npm test | |
env: | |
CI: true | |
release: | |
# Releases are performed via a workflow dispatch | |
if: github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
concurrency: | |
group: release | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v3 | |
- name: π¦ Setup Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: 1.x | |
- name: β Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: π Env | |
run: | | |
echo "Event name: ${{ github.event_name }}" | |
echo "Git ref: ${{ github.ref }}" | |
echo "GH actor: ${{ github.actor }}" | |
echo "SHA: ${{ github.sha }}" | |
VER=`node --version`; echo "Node ver: $VER" | |
VER=`npm --version`; echo "npm ver: $VER" | |
VER=`deno --version`; echo "deno ver: $VER" | |
# The version in the manifest is used to set the version | |
# displayed for the CI. So we need to update version, | |
# prior to building the binaries | |
# | |
# So we update version here. If CI fails, then that bump is | |
# never pushed. If it succeeds, the CI will push any changes to the | |
# manifest, including the version bump, which is what we want | |
- name: πΊ Update Version | |
id: version | |
run: | | |
VERSION=$(deno task bump --version=${INPUT_VERSION}) | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
env: | |
INPUT_VERSION: ${{ github.event.inputs.version }} | |
- name: π Build Binaries | |
id: build_binaries | |
run: | | |
BINARIES_OUTPUT_DIR=$(\ | |
deno task build-cli \ | |
| tail -1 | |
) | |
echo "binaries_output_dir=${BINARIES_OUTPUT_DIR}" >> $GITHUB_OUTPUT | |
env: | |
CI: true | |
# Load the Wallet credentials from the Github secret | |
# This action outputs the filePath, which can be accessed via ${{ steps.wallet_json.outputs.filePath }} | |
- name: πͺͺ Load Wallet | |
uses: timheuer/base64-to-file@v1 | |
id: wallet_json | |
with: | |
fileName: wallet.json | |
encodedString: ${{ secrets.CI_WALLET }} | |
- name: Install Bundlr Client | |
run: | | |
npm i -g @bundlr-network/[email protected] | |
- name: πΎ Publish Binaries to Arweave | |
id: publish_binaries | |
# Bundlr may fail to deploy the binaries to Arweave for a number of reasons | |
# | |
# So before attempting to extract the transaction id from the output | |
# We first check to make sure the success message is output | |
# | |
# If the deploy was successful, bundlr outputs text to stdout, the final line containing | |
# the url of the transaction. We only need the transaction id | |
# | |
# So we tail the output and strip the last part of the printed url | |
# which should be the transaction id | |
run: | | |
bundlr balance ${CI_WALLET_ADDRESS} \ | |
-h ${BUNDLR_NODE} \ | |
-c arweave | |
bundlr price $(du -b "${BINARIES_OUTPUT_DIR}" | cut -f1) \ | |
-h ${BUNDLR_NODE} \ | |
-c arweave | |
BUNDLR_RESULT=$(\ | |
bundlr upload-dir ${BINARIES_OUTPUT_DIR} \ | |
-h ${BUNDLR_NODE} \ | |
-w ${WALLET_FILE} \ | |
-c arweave \ | |
--no-confirmation | |
) | |
echo "${BUNDLR_RESULT}" | |
if [[ -z $(echo "${BUNDLR_RESULT}" | awk '/^Uploaded to https:\/\/arweave.net\//') ]]; then | |
echo "Binaries were not successfully deployed to Bundlr! See above logs." | |
exit 1 | |
fi | |
TRANSACTION_ID=$(\ | |
echo "${BUNDLR_RESULT}" \ | |
| tail -1 \ | |
| awk -F/ '{print $NF}' | |
) | |
echo "tx_id=${TRANSACTION_ID}" >> $GITHUB_OUTPUT | |
env: | |
CI_WALLET_ADDRESS: ${{ secrets.CI_WALLET_ADDRESS }} | |
BINARIES_OUTPUT_DIR: ${{ steps.build_binaries.outputs.binaries_output_dir }} | |
BUNDLR_NODE: https://node2.bundlr.network | |
WALLET_FILE: ${{ steps.wallet_json.outputs.filePath }} | |
- name: π Publish Install Script to Arweave | |
id: publish_install | |
# bundlr outputs text to stdout, the final line containing | |
# the url of the transaction. We only need the transaction id | |
# | |
# So we tail the output and strip the last part of the printed url | |
# which should be the transaction id | |
run: | | |
INSTALL_SCRIPT=$(deno task install-script --binaries=${BINARIES_TRANSACTION_ID}) | |
BUNDLR_RESULT=$(\ | |
bundlr upload ${INSTALL_SCRIPT} \ | |
-h ${BUNDLR_NODE} \ | |
-w ${WALLET_FILE} \ | |
-c arweave \ | |
--no-confirmation | |
) | |
echo "${BUNDLR_RESULT}" | |
if [[ -z $(echo "${BUNDLR_RESULT}" | awk '/^Uploaded to https:\/\/arweave.net\//') ]]; then | |
echo "Binaries were not successfully deployed to Bundlr! See above logs." | |
exit 1 | |
fi | |
TRANSACTION_ID=$(\ | |
echo "${BUNDLR_RESULT}" \ | |
| tail -1 \ | |
| awk -F/ '{print $NF}' | |
) | |
echo "tx_id=${TRANSACTION_ID}" >> $GITHUB_OUTPUT | |
env: | |
BINARIES_TRANSACTION_ID: ${{ steps.publish_binaries.outputs.tx_id }} | |
BUNDLR_NODE: https://node2.bundlr.network | |
WALLET_FILE: ${{ steps.wallet_json.outputs.filePath }} | |
- name: π€ Set Git User | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
# Until we use something like ArNS, we need a way to keep track of the transactions | |
# that contain the ao CLI | |
# | |
# So we will persist the transaction ids into this file, committed as part of this CI | |
- name: πΊοΈ Update txMappings | |
run: | | |
deno task tx-mappings \ | |
--version=${VERSION} \ | |
--binaries=${BINARIES_TRANSACTION_ID} \ | |
--install=${INSTALL_TRANSACTION_ID} \ | |
--latest | |
deno fmt deno.json | |
env: | |
VERSION: ${{ steps.version.outputs.version }} | |
BINARIES_TRANSACTION_ID: ${{ steps.publish_binaries.outputs.tx_id }} | |
INSTALL_TRANSACTION_ID: ${{ steps.publish_install.outputs.tx_id }} | |
- name: β¬οΈ Push | |
# We purposefully don't use "--follow-tags" here | |
# | |
# Git will push tags in parallel when using '--follow-tags'. | |
# So if the tip of trunk has changed, this will cause the tag to be pushed, but not the commit. | |
# | |
# To get around this, we first attempt to push the commit. If it succeeds, the tag is then pushed. | |
# If pushing the commit fails, then the step fails and no tag is pushed up, which is what we want. | |
run: | | |
git add deno.json | |
git commit -m "chore(dev-cli): bump version and update txMappings" | |
git push | |
git push --tags |