Skip to content

Twilson63/ao sdk 20 #13

Twilson63/ao sdk 20

Twilson63/ao sdk 20 #13

Workflow file for this run

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 != 'workflow_dispatch'
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 != 'workflow_dispatch'
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