Skip to content

Merge pull request #25 from axone-protocol/build/use-magefiles #41

Merge pull request #25 from axone-protocol/build/use-magefiles

Merge pull request #25 from axone-protocol/build/use-magefiles #41

Workflow file for this run

name: Publish
on:
push:
branches: [main]
tags: ["v*"]
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
uses: ./.github/workflows/lint.yml
build:
uses: ./.github/workflows/build.yml
schema-matrix:
runs-on: ubuntu-22.04
outputs:
schema: ${{ steps.set-matrix.outputs.schema }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: echo "::set-output name=schema::$(ls schema/ | jq -R -s -c 'split("\n")[:-1]' )"
publish-npm-package:
runs-on: ubuntu-22.04
needs:
- lint
- build
- schema-matrix
strategy:
matrix:
registry:
- url: "https://npm.pkg.github.com"
auth-token-secret: NPM_REGISTRY_TOKEN
- url: "https://registry.npmjs.org"
auth-token-secret: NPM_PUBLIC_REGISTRY_TOKEN
schema: ${{ fromJson(needs.schema-matrix.outputs.schema) }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up context
id: project_context
uses: FranzDiebold/[email protected]
- name: Setup node environment (for publishing)
uses: actions/setup-node@v4
with:
node-version: 18.12
registry-url: ${{ matrix.registry.url }}
scope: "@axone"
- name: Installing quicktype
run: |
yarn global add quicktype
echo "$(yarn global bin)" >> $GITHUB_PATH
- name: Prepare package path
id: package
run: |
SCHEMA=${{ matrix.schema }}
PACKAGE_SRC=$(echo "ts/${SCHEMA/axone-/""}-schema")
mkdir ${PACKAGE_SRC}/gen-ts
echo "DESTINATION=$(echo "ts/${SCHEMA/axone-/""}-schema")" >> $GITHUB_OUTPUT
- name: Generate sources
run: |
quicktype -s schema schema/${{ matrix.schema }}/*.json -o ${{ steps.package.outputs.DESTINATION }}/gen-ts/schema.ts --prefer-types --prefer-unions
- name: Publish package
run: |
set -eu
yarn --cwd ${{ steps.package.outputs.DESTINATION }} && yarn --cwd ${{ steps.package.outputs.DESTINATION }} build
DATE=$(date +%Y%m%d%H%M%S)
publish=(yarn --cwd ${{ steps.package.outputs.DESTINATION }} publish --access=public --no-git-tag-version --non-interactive)
if [[ $GITHUB_REF == refs/tags/v* ]]; then
publish+=(--tag latest)
else
publish+=(--prerelease --preid next.$DATE --tag next)
fi
echo "🚀 Publishing npm package with following command line: ${publish[@]}"
"${publish[@]}"
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.registry.auth-token-secret] }}
- name: Create release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body: Schema changelog avalaible on [contract repository](https://github.com/axone-protocol/contracts/blob/${{ github.ref_name }}/CHANGELOG.md).