Skip to content

Update schema

Update schema #161

Workflow file for this run

name: Update schema
concurrency: update-schema-${{ github.ref }}
on:
workflow_dispatch:
inputs:
ref:
description: "New okp4/contracts version (repository tag or repository ref)"
required: true
draft:
type: boolean
description: "Indicate if schemas need to be only publish in draft or need to be released and published publicly"
required: false
default: false
jobs:
update-schema:
runs-on: ubuntu-22.04
steps:
- name: Checks params
run: |
if [[ ! ${{ github.event.inputs.ref }} =~ ^v[0-9]+(\.[0-9]+)* ]] && [[ ! ${{ github.event.inputs.ref }} = "main" ]]; then
>&2 echo "❌ Invalid github ref given '${{ github.event.inputs.ref }}', should be eithier 'main' or 'v*'."
exit 1
fi
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ secrets.OKP4_TOKEN }}
fetch-depth: 2
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref }}
repository: okp4/contracts
token: ${{ secrets.OKP4_TOKEN }}
path: tmp
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Setup rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.69
default: true
override: true
- name: Install cargo make
uses: davidB/rust-cargo-make@v1
- name: Build schema
run: |
cd tmp
cargo make schema
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.OKP4_BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OKP4_BOT_GPG_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Install gomplate
run: |
curl -s -L -o /usr/local/bin/gomplate https://github.com/hairyhenderson/gomplate/releases/download/v3.11.5/gomplate_linux-amd64
chmod +x /usr/local/bin/gomplate
- name: Copy updated schema and generate README
run: |
rm -rf schema/*
rsync -rmv --include='*/' --include='*/schema/raw/*.json' --exclude='*' tmp/contracts/ schema/
find schema -type f -name "*.json" -exec sh -c 'mv "{}" "$(dirname "{}" | xargs dirname | xargs dirname)"' \;
CONTRACTS=$(ls schema/ | jq -R -s -c 'split("\n")[:-1]')
for CONTRACT in $(echo ${CONTRACTS} | jq -r '.[]'); do
NAME=${CONTRACT/okp4-/""}
SCHEMA_NAME=$NAME-schema
jq -n --rawfile docs tmp/docs/$CONTRACT.md \
--arg name "$NAME" \
--arg contract_name "$CONTRACT" \
--arg schema_name "$SCHEMA_NAME" \
--arg ref "${{ github.event.inputs.ref }}" \
'{docs: $docs, name: $name, contract_name: $contract_name, schema_name: $schema_name, ref: $ref}' > data.json
echo "📄 Generate $CONTRACT_NAME readme.md..."
gomplate -f ts/README.md.template -d data.json -o ts/$SCHEMA_NAME/README.md
rm data.json
done
git rm --ignore-unmatch --cached tmp
rm -rf .git/modules/tmp
rm -rf tmp
- name: Setup node environment
uses: actions/setup-node@v3
with:
node-version: 18.12
- name: "[TS] Bump npm package version"
if: ${{ github.event.inputs.draft == 'false' }}
run: |
find ts/* -maxdepth 0 -type d -exec sh -c 'cd {} && yarn version --new-version ${{ github.event.inputs.ref }} --allow-same-version --no-git-tag-version' \;
- name: Commit documentation draft
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_user_name: ${{ secrets.OKP4_BOT_GIT_COMMITTER_NAME }}
commit_user_email: ${{ secrets.OKP4_BOT_GIT_COMMITTER_EMAIL }}
commit_author: ${{ secrets.OKP4_BOT_GIT_AUTHOR_NAME }} <${{ secrets.OKP4_BOT_GIT_AUTHOR_EMAIL }}>
commit_message: "${{ github.event.inputs.draft == 'true' && 'feat: update schema files' || 'chore(release): perform release' }} ${{ github.event.inputs.draft == 'false' && github.event.inputs.ref || '' }}"
tagging_message: ${{ github.event.inputs.draft == 'false' && github.event.inputs.ref || '' }}
file_pattern: '*.json */README.md'