Improve release process (#63) #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Draft Release | |
on: | |
push: | |
branches: [ "main" ] | |
paths: [ "CHANGELOG.md" ] | |
workflow_dispatch: | |
jobs: | |
collect-release-information: | |
runs-on: ubuntu-latest | |
outputs: | |
should-release: ${{ steps.run.outputs.should-release }} | |
version: ${{ steps.run.outputs.version }} | |
steps: | |
- uses: actions/checkout@v2 | |
- id: run | |
run: | | |
echo "should-release=$(.github/changelog-processor.py CHANGELOG.md --should-release)" >> $GITHUB_OUTPUT | |
echo "version=$(.github/changelog-processor.py CHANGELOG.md --print-latest-version)" >> $GITHUB_OUTPUT | |
cat $GITHUB_OUTPUT | |
runtime-matrix: | |
needs: [ collect-release-information ] | |
if: needs.collect-release-information.outputs.should-release == '1' | |
runs-on: ubuntu-latest | |
outputs: | |
runtime: ${{ steps.runtime.outputs.runtime }} | |
steps: | |
- uses: actions/checkout@v2 | |
- id: runtime | |
run: | | |
TASKS=$(echo $(cat .github/workflows/release-matrix.json) | sed 's/ //g' ) | |
echo $TASKS | |
echo "runtime=$TASKS" >> $GITHUB_OUTPUT | |
build-runtimes: | |
needs: [ runtime-matrix ] | |
continue-on-error: true | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Cache target dir | |
uses: actions/cache@v3 | |
with: | |
path: "${{ github.workspace }}/${{ matrix.runtime.path }}/target" | |
key: srtool-target-${{ matrix.runtime.path }}-${{ matrix.runtime.name }}-${{ github.sha }} | |
restore-keys: | | |
srtool-target-${{ matrix.runtime.path }}-${{ matrix.runtime.name }}- | |
srtool-target-${{ matrix.runtime.path }}- | |
- name: Build ${{ matrix.runtime.name }} | |
id: srtool_build | |
uses: chevdor/[email protected] | |
env: | |
BUILD_OPTS: "--features on-chain-release-build" | |
with: | |
chain: ${{ matrix.runtime.name }} | |
package: ${{ matrix.runtime.package }} | |
runtime_dir: ${{ matrix.runtime.path }} | |
profile: "production" | |
- name: Store ${{ matrix.runtime.name }} srtool digest to disk | |
run: | | |
echo '${{ steps.srtool_build.outputs.json }}' | jq > ${{ matrix.runtime.name }}_srtool_output.json | |
- name: Upload ${{ matrix.runtime.name }} srtool json | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.runtime.name }}-srtool-json | |
path: ${{ matrix.runtime.name }}_srtool_output.json | |
- name: Upload ${{ matrix.runtime.name }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.runtime.name }} | |
path: | | |
${{ steps.srtool_build.outputs.wasm_compressed }} | |
publish-release: | |
runs-on: ubuntu-latest | |
needs: [ build-runtimes, collect-release-information ] | |
outputs: | |
release_url: ${{ steps.create-release.outputs.html_url }} | |
asset_upload_url: ${{ steps.create-release.outputs.upload_url }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Download srtool json output | |
uses: actions/download-artifact@v3 | |
- name: Archive context output | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release-notes-context | |
path: | | |
**/*_srtool_output.json | |
- name: Add runtime info to changelog | |
run: | | |
CONTEXT=$(find . -name '*_srtool_output.json') | |
SRTOOL() { <$(<<<$CONTEXT head -n1) jq -r .$1; } | |
WASM() { <${JSON} jq -r ".runtimes.compressed.subwasm.$1"; } | |
tee -a DRAFT <<-EOF | |
EOF | |
tee -a DRAFT <CHANGELOG.md | |
tee -a DRAFT <<-EOF | |
## Runtime info | |
*These runtimes were built with **$(SRTOOL rustc)** using **[$(SRTOOL gen)](https://github.com/paritytech/srtool)*** | |
EOF | |
for JSON in $(<<<$CONTEXT sort -sr) | |
do tee -a DRAFT <<-EOF | |
### $(WASM 'core_version.specName / "-" | map(. / "" | first |= ascii_upcase | add) | join(" ")') | |
~~~ | |
🏋️ Runtime Size: $(numfmt --to iec-i --format "%.2f" $(WASM size)) ($(WASM size) bytes) | |
🗜 Compressed: $(WASM 'compression | if .compressed then "Yes: \(1 - .size_compressed / .size_decompressed | . * 10000 | round / 100)%" else "No" end') | |
🔥 Core Version: $(WASM 'core_version | "\(.specName)-\(.specVersion) \(.implName)-\(.implVersion).tx\(.transactionVersion).au\(.authoringVersion)"') | |
🎁 Metadata version: V$(WASM metadata_version) | |
🗳️ Blake2-256 hash: $(WASM blake2_256) | |
📦 IPFS: $(WASM ipfs_hash) | |
~~~ | |
EOF | |
done | |
- name: Create release | |
id: create-release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ format('v{0}', needs.collect-release-information.outputs.version) }} | |
release_name: Runtimes ${{ needs.collect-release-information.outputs.version }} | |
body_path: DRAFT | |
draft: false | |
publish-runtimes: | |
needs: [ runtime-matrix, publish-release ] | |
continue-on-error: true | |
runs-on: ubuntu-latest | |
env: | |
RUNTIME_DIR: runtime | |
strategy: | |
matrix: | |
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v3 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
- name: Get runtime info | |
env: | |
JSON: release-notes-context/${{ matrix.runtime.name }}-srtool-json/${{ matrix.runtime.name }}_srtool_output.json | |
run: | | |
>>$GITHUB_ENV echo ASSET=$(find ${{ matrix.runtime.name }} -name '*.compact.compressed.wasm') | |
>>$GITHUB_ENV echo SPEC=$(<${JSON} jq -r .runtimes.compact.subwasm.core_version.specVersion) | |
>>$GITHUB_ENV echo TXVER=$(<${JSON} jq -r .runtimes.compact.subwasm.core_version.transactionVersion) | |
- name: Upload compressed ${{ matrix.runtime.name }} v${{ env.SPEC }} tx${{ env.TXVER }} wasm | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }} | |
asset_path: ${{ env.ASSET }} | |
asset_name: ${{ matrix.runtime.name }}_runtime-v${{ env.SPEC }}.tx${{ env.TXVER }}.compact.compressed.wasm | |
asset_content_type: application/wasm |