From 63efabc159a3f15f41cb94da313fc736a4c6bb01 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 2 Aug 2022 16:46:55 +0200 Subject: [PATCH] gh action to find chain and scope on release branch pushed (#2304) --- .github/scripts/setup-env.py | 26 ++++++++++ .github/workflows/publish-release.yml | 72 ++++++++++++++++----------- 2 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 .github/scripts/setup-env.py diff --git a/.github/scripts/setup-env.py b/.github/scripts/setup-env.py new file mode 100644 index 0000000000..693a7832a5 --- /dev/null +++ b/.github/scripts/setup-env.py @@ -0,0 +1,26 @@ +import os +import re + +regex = r"release-(karura|acala)-(\d+\.\d+\.\d+)" + +# find chain and version from current branch +x = re.search(regex, os.getenv("GITHUB_REF")) +chain = x.group(1) +version = x.group(2) + +branches = os.popen("git branch -a | grep remotes/origin/release-{}-".format(chain)).read().split("\n") +branches = map(lambda x: x.strip(), branches) +branches = list(filter(None, branches)) +# select previous branch +previous_branches = branches[-2] + +# find previous version +x = re.search(regex, previous_branches) +previous_version = x.group(2) + +is_patch = previous_version.split(".")[1] == version.split(".")[1] +scope = "runtime" if is_patch else "full" + +with open(os.getenv("GITHUB_ENV"), "a") as env: + env.write("CHAIN={}\n".format(chain)) + env.write("SCOPE={}\n".format(scope)) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index ddc9b8c935..12ea0391ac 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -6,18 +6,18 @@ name: Publish Release # - Use subwasm to obtain build data # - Generate release note # - Create release issue -# - Archive the build artifacts to Github +# - Archive the build artifacts to Github # - Publish the WASM to Pinata via ipfs -env: - SUBWASM_VERSION: 0.17.0 - on: + push: + branches: + - "release-(karura|acala)-**" workflow_dispatch: inputs: # Get name of the chain chain: - description: Chain Runtime (default = karura) + description: Chain Runtime (default = karura) required: true default: karura type: choice @@ -40,6 +40,11 @@ on: description: Default to use the latest. You can use an alternate image, use with caution! required: false +env: + SUBWASM_VERSION: 0.17.0 + CHAIN: ${{ github.event.inputs.chain }} + SCOPE: ${{ github.event.inputs.scope }} + jobs: build-release: name: Build and publish ${{ github.event.inputs.chain }} @@ -51,6 +56,15 @@ jobs: with: submodules: true + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Setup ENV + if: ${{ env.CHAIN == '' || env.SCOPE == '' }} + run: python .github/scripts/setup-env.py + # Build WASM with Substrate Runtime Tool - name: Srtool build id: srtool_build @@ -58,14 +72,14 @@ jobs: env: BUILD_OPTS: "--features on-chain-release-build,no-metadata-docs" with: - chain: ${{ github.event.inputs.chain }} + chain: ${{ env.CHAIN }} tag: ${{ github.event.inputs.srtool_image }} # Output the build summary - name: Build Summary run: | - echo '${{ steps.srtool_build.outputs.json }}' | jq . > ${{ github.event.inputs.chain }}-srtool-digest.json - cat ${{ github.event.inputs.chain }}-srtool-digest.json + echo '${{ steps.srtool_build.outputs.json }}' | jq . > ${{ env.CHAIN }}-srtool-digest.json + cat ${{ env.CHAIN }}-srtool-digest.json echo "Runtime location: ${{ steps.srtool_build.outputs.wasm }}" # install subwasm @@ -78,29 +92,29 @@ jobs: # Display information for wasm - name: Extract metadata run: | - subwasm --json info ${{ steps.srtool_build.outputs.wasm }} > ${{ github.event.inputs.chain }}-info.json - subwasm info ${{ steps.srtool_build.outputs.wasm }} > ${{ github.event.inputs.chain }}-info.txt - cat ${{ github.event.inputs.chain }}-info.txt + subwasm --json info ${{ steps.srtool_build.outputs.wasm }} > ${{ env.CHAIN }}-info.json + subwasm info ${{ steps.srtool_build.outputs.wasm }} > ${{ env.CHAIN }}-info.txt + cat ${{ env.CHAIN }}-info.txt - subwasm --json info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ github.event.inputs.chain }}-subwam-info.json - subwasm info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ github.event.inputs.chain }}-subwam-info.txt - cat ${{ github.event.inputs.chain }}-subwam-info.txt + subwasm --json info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ env.CHAIN }}-subwam-info.json + subwasm info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ env.CHAIN }}-subwam-info.txt + cat ${{ env.CHAIN }}-subwam-info.txt # Diff new wasm with current - name: Check the metadata diff run: | - subwasm diff ${{ steps.srtool_build.outputs.wasm }} --chain-b ${{ github.event.inputs.chain }} | tee ${{ github.event.inputs.chain }}-diff.txt + subwasm diff ${{ steps.srtool_build.outputs.wasm }} --chain-b ${{ env.CHAIN }} | tee ${{ env.CHAIN }}-diff.txt # Generate release notes - name: Generate note id: generate-note uses: AcalaNetwork/acala-release-note-action@master with: - scope: ${{ github.event.inputs.scope }} - chain: ${{ github.event.inputs.chain }} - subwasm_info: ${{ github.event.inputs.chain }}-subwam-info.txt - srtool_details: ${{ github.event.inputs.chain }}-srtool-digest.json - + scope: ${{ env.SCOPE }} + chain: ${{ env.CHAIN }} + subwasm_info: ${{ env.CHAIN }}-subwam-info.txt + srtool_details: ${{ env.CHAIN }}-srtool-digest.json + # Create release checklist issue - name: Crate Release Checklist issue uses: JasonEtco/create-an-issue@v2 @@ -108,20 +122,20 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: filename: ${{ steps.generate-note.outputs.release-note }} - - - name: Archive Artifacts for ${{ github.event.inputs.chain }} + + - name: Archive Artifacts for ${{ env.CHAIN }} uses: actions/upload-artifact@v2 with: - name: ${{ github.event.inputs.chain }}-runtime + name: ${{ env.CHAIN }}-runtime path: | ${{ steps.srtool_build.outputs.wasm }} ${{ steps.srtool_build.outputs.wasm_compressed }} - ${{ github.event.inputs.chain }}-srtool-digest.json - ${{ github.event.inputs.chain }}-metadata.json - ${{ github.event.inputs.chain }}-metadata.txt - ${{ github.event.inputs.chain }}-subwam-info.json - ${{ github.event.inputs.chain }}-subwam-info.txt - ${{ github.event.inputs.chain }}-diff.txt + ${{ env.CHAIN }}-srtool-digest.json + ${{ env.CHAIN }}-metadata.json + ${{ env.CHAIN }}-metadata.txt + ${{ env.CHAIN }}-subwam-info.json + ${{ env.CHAIN }}-subwam-info.txt + ${{ env.CHAIN }}-diff.txt - name: Upload wasm to pinata uses: aquiladev/ipfs-action@v0.1.6