π¨βπ» Test & Deploy AO CLI #4
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 Dev 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 | |
release: | |
# Releases are performed via a workflow dispatch | |
if: github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v3 | |
- name: π¦ Setup Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: 1.x | |
# Until we use something more comprehensive | |
# this simple check of the provided version will suffice | |
- name: π« Check Inputs | |
id: check_inputs | |
run: | | |
VERSION=$(deno run https://deno.land/x/semver/cli.ts clean "${INPUT_VERSION}") | |
if [[ "$VERSION" == "undefined" ]]; then | |
echo "${INPUT_VERSION} is not a valid semver version" 1>&2 | |
exit 1 | |
fi | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
env: | |
INPUT_VERSION: ${{ github.event.inputs.version }} | |
- name: π Build Binaries | |
id: build_binaries | |
run: | | |
BINARIES_OUTPUT_DIR=$(\ | |
tools/build.sh \ | |
| 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: β Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- 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 run -A tools/create-install-script.js --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 hyperbeam CLI | |
# | |
# So we will persist the transaction ids into this file, committed as part of this CI | |
- name: πΊοΈ Update txMappings | |
run: | | |
deno run -A tools/update-tx-mappings.js \ | |
--version=${VERSION} \ | |
--binaries=${BINARIES_TRANSACTION_ID} \ | |
--install=${INSTALL_TRANSACTION_ID} \ | |
--latest | |
env: | |
VERSION: ${{ steps.check_inputs.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 egg.json | |
git commit -m "chore(dev-cli): bump version and update txMappings" | |
git push | |
git push --tags |