Ppe/fixes 2 #5
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 != 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
deno-version: [1.x] | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v4 | |
- 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-node-commands: | |
if: github.event_name != 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v4 | |
- name: β Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: π₯ Download deps | |
working-directory: dev-cli/container/src/node | |
run: | | |
npm i | |
- name: β‘ Run Tests | |
working-directory: dev-cli/container/src/node | |
run: | | |
npm test | |
env: | |
CI: true | |
release: | |
# Releases are performed via a workflow dispatch | |
if: github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
concurrency: | |
group: release | |
steps: | |
- name: β¬οΈ Checkout repo | |
uses: actions/checkout@v4 | |
- name: π¦ Setup Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: 1.x | |
- name: β Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: π₯ Download deps | |
working-directory: dev-cli/tools/deploy | |
run: | | |
npm i | |
- 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" | |
- name: π¬ Decode Wallet JSON File | |
uses: timheuer/base64-to-file@v1 | |
id: wallet_file | |
with: | |
fileName: wallet.json | |
encodedString: ${{ secrets.CI_WALLET }} | |
# 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-binaries \ | |
| tail -1 | |
) | |
echo "binaries_output_dir=${BINARIES_OUTPUT_DIR}" >> $GITHUB_OUTPUT | |
env: | |
CI: true | |
- name: Install ArDrive CLI | |
run: | | |
npm i -g ardrive-cli@2 | |
- name: πΎ Publish Binaries to Arweave | |
id: publish_binaries | |
# | |
# Use the ArDrive CLI to: | |
# - create a new folder in the ao CLI Artifacts Drive | |
# - upload binaries to that folder | |
# - create a manifest of the folder | |
# We also add additional tags in order to mint $U | |
# | |
run: | | |
echo "Creating folder for binaries on ArDrive..." | |
ARDRIVE_FOLDER_RESULT=$(\ | |
ardrive create-folder \ | |
--turbo \ | |
--parent-folder-id "${ARDRIVE_FOLDER_ID}" \ | |
--folder-name "${VERSION}" \ | |
-w "${WALLET}" | |
) | |
echo "${ARDRIVE_FOLDER_RESULT}" | |
FOLDER_ID=$(\ | |
echo "${ARDRIVE_FOLDER_RESULT}" \ | |
| jq -r '.created[0].entityId' | |
) | |
until ardrive folder-info \ | |
--folder-id \ | |
"${FOLDER_ID}"; do | |
echo "ArDrive folder has not yet synced. Sleeping for 2 seconds..." | |
sleep 2 | |
done | |
echo "Uploading Binaries..." | |
ardrive upload-file \ | |
--turbo \ | |
--parent-folder-id "${FOLDER_ID}" \ | |
--local-paths "${BINARIES_OUTPUT_DIR}"/*.zip \ | |
-w "${WALLET}" | |
until [[ $(ardrive list-folder \ | |
--parent-folder-id "${FOLDER_ID}" \ | |
| jq 'length') -ge 4 ]]; do | |
echo "ArDrive folder binaries have not yet synced. Sleeping for 2 seconds..." | |
sleep 2 | |
done | |
echo "Generating Manifest..." | |
ARDRIVE_MANIFEST_RESULTS=$(\ | |
ardrive create-manifest \ | |
--turbo \ | |
-f "${FOLDER_ID}" \ | |
-w "${WALLET}" | |
) | |
echo "${ARDRIVE_MANIFEST_RESULTS}" | |
BINARIES_TRANSACTION_ID=$(\ | |
echo "${ARDRIVE_MANIFEST_RESULTS}" \ | |
| jq -r '.created[0].dataTxId' | |
) | |
echo "folder_id=${FOLDER_ID}" >> $GITHUB_OUTPUT | |
echo "tx_id=${BINARIES_TRANSACTION_ID}" >> $GITHUB_OUTPUT | |
env: | |
WALLET: ${{ steps.wallet_file.outputs.filePath }} | |
VERSION: ${{ steps.version.outputs.version }} | |
BINARIES_OUTPUT_DIR: ${{ steps.build_binaries.outputs.binaries_output_dir }} | |
ARDRIVE_FOLDER_ID: ${{ secrets.CLI_ARDRIVE_FOLDER_ID }} | |
- name: π Build Install Script | |
id: build_install_script | |
run: | | |
INSTALL_SCRIPT=$(deno task build-install-script --binaries=${BINARIES_TRANSACTION_ID}) | |
echo "install_script=${INSTALL_SCRIPT}" >> $GITHUB_OUTPUT | |
env: | |
CI: true | |
BINARIES_TRANSACTION_ID: ${{ steps.publish_binaries.outputs.tx_id }} | |
# | |
# Use the ArDrive CLI to: | |
# - upload the install script to the same folder | |
# | |
# Then finally trigger script to update ArNS for install-ao | |
- name: π Publish Install Script to Arweave | |
id: publish_install | |
# We output 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: | | |
echo "Uploading Install Script..." | |
ARDRIVE_FILE_RESULTS=$(\ | |
ardrive upload-file \ | |
--turbo \ | |
--parent-folder-id "${FOLDER_ID}" \ | |
--local-path "${INSTALL_SCRIPT}" \ | |
-w "${WALLET}" | |
) | |
echo "${ARDRIVE_FILE_RESULTS}" | |
INSTALL_TRANSACTION_ID=$(\ | |
echo "${ARDRIVE_FILE_RESULTS}" \ | |
| jq -r '.created[0].dataTxId' | |
) | |
INSTALL_SCRIPT_ID="${INSTALL_TRANSACTION_ID}" deno task arns-install-script | |
echo "tx_id=${INSTALL_TRANSACTION_ID}" >> $GITHUB_OUTPUT | |
env: | |
WALLET: ${{ steps.wallet_file.outputs.filePath }} | |
FOLDER_ID: ${{ steps.publish_binaries.outputs.folder_id }} | |
INSTALL_SCRIPT: ${{ steps.build_install_script.outputs.install_script }} | |
- 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 src/versions.js | |
git commit -m "chore(dev-cli): bump version and update txMappings" | |
git push | |
git push --tags |