Skip to content

Commit

Permalink
Extract updating featurenet to separate action and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajgs committed Jan 26, 2024
1 parent 134c16a commit 40775ca
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 17 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/_featurenet-create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ on:
type: string
required: false
default: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
update:
description: |
Perform update instead of create, and do not change values of validators, expiration,
internal and sudo-account-id
required: false
type: boolean
default: false
outputs:
ws-hostname:
description: Hostname of the WS endpoint
Expand Down Expand Up @@ -122,8 +115,8 @@ jobs:
override: true
debug: true

- name: Upsert featurenet with image tag
uses: Cardinal-Cryptography/github-actions/create-featurenet@v6
- name: Create featurenet with image tag
uses: Cardinal-Cryptography/github-actions/create-featurenet@A0-3761-tweak-naming-for-more-clarity
id: create-featurenet
with:
gh-ci-user: ${{ secrets.CI_GH_USER }}
Expand All @@ -140,7 +133,6 @@ jobs:
git-commit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
wait-for-finalized-heads: "true"
sudo-account-id: ${{ inputs.sudo-account-id }}
update: ${{ inputs.update && 'true' || 'false' }}

- name: Finish featurenet Deployment
uses: bobheadxi/deployments@v1
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/_featurenet-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
name: FE - Create

on:
workflow_call:
inputs:
featurenet-name:
description: 'Name of the featurenet'
required: true
type: string
aleph-node-image:
description: "FQDN of aleph-node image"
required: true
type: string
rolling-update-partition:
description: |
Number from 0 to N-1, where N is size of am existing featurenet.
All aleph-node-validator-N with an ordinal N that is great than or equal to the partition
will be updated. If not specified, all nodes will be updated.
required: false
default: '0'
type: string
outputs:
ws-hostname:
description: Hostname of the WS endpoint
value: ${{ jobs.create-featurenet.outputs.ws-hostname }}

jobs:
validate-inputs:
name: Validate inputs
runs-on: ubuntu-20.04
steps:
- name: Validate inputs
shell: bash
# yamllint disable rule:line-length
run: |
if [[ ! '${{ inputs.featurenet-name }}' =~ ^[a-z0-9][a-z0-9\-]{4,48}$ ]]
then
echo '!!! Invalid featurenet name'
exit 1
fi
if [[ ! '${{ inputs.aleph-node-image }}' =~ ^[a-z0-9][a-z0-9\._:/\-]{1,52}$ ]]; then
echo "!!! Invalid aleph-node image"
exit 1
fi
# yamllint enable rule:line-length

check-vars-and-secrets:
needs: [validate-inputs]
name: Check vars and secrets
uses: ./.github/workflows/_check-vars-and-secrets.yml
secrets: inherit

create-featurenet:
needs: [check-vars-and-secrets]
name: Create featurenet
runs-on: [self-hosted, Linux, X64, small]
outputs:
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
ws-hostname: ${{ steps.create-featurenet.outputs.ws-hostname }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Start featurenet Deployment
uses: bobheadxi/[email protected]
id: deployment
with:
step: start
token: ${{ secrets.CI_GH_TOKEN }}
env: ${{ inputs.featurenet-name }}
override: true
debug: true

- name: Update featurenet with image tag
uses: Cardinal-Cryptography/github-actions/update-featurenet@A0-3761-tweak-naming-for-more-clarity
id: create-featurenet
with:
gh-ci-user: ${{ secrets.CI_GH_USER }}
gh-ci-token: ${{ secrets.CI_GH_TOKEN }}
argo-sync-user-token: ${{ secrets.ARGO_SYNC_USER_TOKEN }}
repo-featurenet-template-name: ${{ secrets.REPO_FEATURENET_TEMPLATE_NAME }}
featurenet-name: ${{ inputs.featurenet-name }}
featurenet-aleph-node-image: ${{ inputs.aleph-node-image }}
rolling-update-partition: ${{ inputs.rolling-update-partition }}
git-commit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }}
git-commit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
wait-for-finalized-heads: "true"

- name: Finish featurenet Deployment
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.CI_GH_TOKEN }}
status: ${{ job.status }}
env: ${{ inputs.featurenet-name }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
# yamllint disable-line rule:line-length
env_url: https://dev.azero.dev/?rpc=wss%3A%2F%2F${{ steps.create-featurenet.outputs.ws-hostname }}#/explorer
debug: true
9 changes: 2 additions & 7 deletions create-featurenet/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ inputs:
description: 'Sudo account ID'
required: false
default: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
update:
description: 'Perform update instead of create, and do not change values of validators, expiration, internal and sudo-account-id'
required: false
default: "false"
outputs:
ws-hostname:
description: Hostname of the WS endpoint
Expand Down Expand Up @@ -124,7 +120,7 @@ runs:
repository: Cardinal-Cryptography/${{ inputs.repo-featurenet-template-name }}
token: ${{ inputs.gh-ci-token }}
path: "${{ inputs.repo-featurenet-template-name }}"
ref: main
ref: A0-3761-tweak-naming-for-more-clarity

- name: Start featurenet
id: start-featurenet
Expand All @@ -138,15 +134,14 @@ runs:
run: |
cd '${{ inputs.repo-featurenet-template-name }}'
./create-featurenet.sh \
./upsert-featurenet.sh \
'${{ inputs.featurenet-name }}' \
'${{ inputs.featurenet-aleph-node-image }}' \
'${{ inputs.validators }}' \
'${{ inputs.rolling-update-partition }}' \
'${{ inputs.expiration }}' \
'${{ inputs.sudo-account-id }}' \
${{ inputs.internal == 'true' && '-i' || '' }} \
${{ inputs.update == 'true' && '-u' || '' }} \
-c -g | tee -a tmp-opssh-createfeaturenet-output.txt
ws_hostname=$(cat tmp-opssh-createfeaturenet-output.txt | grep '^__output:ws-hostname:' | cut -d: -f3)
Expand Down
126 changes: 126 additions & 0 deletions update-featurenet/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
name: Create featurenet
description: |
This action is used in several dev flows to
* spawn new featurenet from any aleph node git ref,
* update binary in the existing featurenet,
* update rolling partition in the existing featurenet,
inputs:
gh-ci-user:
description: 'GH user to be used in the action'
required: true
gh-ci-token:
description: 'GH token to be used in the action'
required: true
repo-featurenet-template-name:
description: 'Name of the repository containing featurenet template'
required: true
argo-sync-user-token:
description: 'ArgoCD user token to be used in the action'
required: true
featurenet-name:
description: 'Name of featurenet'
required: true
git-commit-author:
description: 'Git commit author when pushing to featurenets repository'
required: true
git-commit-email:
description: 'Git commit email when pushing to featurenets repository'
required: true
featurenet-aleph-node-image:
description: 'aleph-node docker image tag'
required: true
default: ''
rolling-update-partition:
description: |
Number from 0 to N-1, where N is size of am existing featurenet.
All aleph-node-validator-N with an ordinal N that is great than or equal to the partition
will be updated. If not specified, all nodes will be updated.
required: false
default: "0"
wait-for-finalized-heads:
description: 'Wait for heads finalization'
required: false
default: "false"
outputs:
ws-hostname:
description: Hostname of the WS endpoint
value: ${{ steps.start-featurenet.outputs.ws-hostname }}

runs:
using: "composite"
steps:
- name: Validate inputs
shell: bash
run: |
if [[
! '${{ inputs.featurenet-name }}' =~ ^[a-z0-9][a-z0-9\-]{4,48}$
]]
then
echo "!!! Invalid featurenet name"
exit 1
fi
if [[
! '${{ inputs.featurenet-aleph-node-image }}' =~ ^[a-z0-9][a-z0-9\._/:\-]{1,52}$
]]
then
echo "!!! Invalid featurenet node image tag"
exit 1
fi
if [[
'${{ inputs.rolling-update-partition }}' != "" && \
! '${{ inputs.rolling-update-partition }}' =~ ^[0-9]$
]]
then
echo "!!! Expected rolling update partition to be a cardinal value from 0 to 9"
exit 1
fi
- name: Checkout featurenet template repo
uses: actions/checkout@v3
with:
repository: Cardinal-Cryptography/${{ inputs.repo-featurenet-template-name }}
token: ${{ inputs.gh-ci-token }}
path: "${{ inputs.repo-featurenet-template-name }}"
ref: A0-3761-tweak-naming-for-more-clarity

- name: Start featurenet
id: start-featurenet
shell: bash
env:
GITHUB_USERNAME: ${{ inputs.gh-ci-user }}
GITHUB_TOKEN: ${{ inputs.gh-ci-token }}
GIT_COMMIT_USER_NAME: ${{ inputs.git-commit-author }}
GIT_COMMIT_USER_EMAIL: ${{ inputs.git-commit-email }}
# yamllint disable rule:line-length
run: |
cd '${{ inputs.repo-featurenet-template-name }}'
./upsert-featurenet.sh \
'${{ inputs.featurenet-name }}' \
'${{ inputs.featurenet-aleph-node-image }}' \
'not-used-because-update' \
'${{ inputs.rolling-update-partition }}' \
'not-used-because-update' \
'not-used-because-update' \
-u \
-c -g | tee -a tmp-opssh-updatefeaturenet-output.txt
ws_hostname=$(cat tmp-opssh-updatefeaturenet-output.txt | grep '^__output:ws-hostname:' | cut -d: -f3)
echo "ws-hostname=${ws_hostname}" >> $GITHUB_OUTPUT
# yamllint enable rule:line-length

- name: Refresh Argo and wait for the creation to be finished
shell: bash
run: |
cd '${{ inputs.repo-featurenet-template-name }}'
./refresh-featurenets.sh '${{ inputs.argo-sync-user-token }}' '${{ inputs.featurenet-name }}'
- name: Wait for the unique consecutive finalized heads
if: inputs.wait-for-finalized-heads == 'true'
shell: bash
run: |
cd '${{ inputs.repo-featurenet-template-name }}'
./wait-for-featurenet-finalized-heads.sh '${{ inputs.featurenet-name }}'

0 comments on commit 40775ca

Please sign in to comment.