Skip to content

Commit

Permalink
gh action to find chain and scope on release branch pushed (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Aug 2, 2022
1 parent 1d98cdb commit 63efabc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 29 deletions.
26 changes: 26 additions & 0 deletions .github/scripts/setup-env.py
Original file line number Diff line number Diff line change
@@ -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))
72 changes: 43 additions & 29 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -51,21 +56,30 @@ 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
uses: chevdor/srtool-actions@v0.4.0
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
Expand All @@ -78,50 +92,50 @@ 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
env:
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
Expand Down

0 comments on commit 63efabc

Please sign in to comment.