From fc67b537b3d1e7eb9bf5175e3d4c7dccaa29ae44 Mon Sep 17 00:00:00 2001 From: b-yap <2826165+b-yap@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:31:12 +0800 Subject: [PATCH] added a script for cleaning up commits and the srtool --- .github/workflows/sr-tool.yml | 76 +++++++++++++++++++ ...levant_commit_of_runtime_since_last_tag.sh | 56 ++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 .github/workflows/sr-tool.yml create mode 100755 scripts/get_relevant_commit_of_runtime_since_last_tag.sh diff --git a/.github/workflows/sr-tool.yml b/.github/workflows/sr-tool.yml new file mode 100644 index 0000000000..4eb267fc57 --- /dev/null +++ b/.github/workflows/sr-tool.yml @@ -0,0 +1,76 @@ +name: Srtool build + +env: + SUBWASM_VERSION: 0.20.0 + +on: + pull_request: + types: [opened, edited, synchronize] + branches: + - main + +jobs: + build: + if: "contains(github.event.pull_request.title, 'Release')" + name: Build ${{ matrix.chain }} ${{ github.event.inputs.ref }} + strategy: + fail-fast: false + matrix: + chain: ["amplitude", "pendulum"] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref }} + fetch-depth: 0 + + - name: Srtool build + id: srtool_build + uses: chevdor/srtool-actions@v0.9.2 + with: + chain: ${{ matrix.chain }} + runtime_dir: runtime/${{ matrix.chain }} + # this is important to avoid build fail. See https://github.com/paritytech/srtool/issues/62 + tag: 1.66.1 + - name: Summary + run: | + echo '${{ steps.srtool_build.outputs.json }}' | jq > ${{ matrix.chain }}-srtool-digest.json + cat ${{ matrix.chain }}-srtool-digest.json + echo "Runtime location: ${{ steps.srtool_build.outputs.wasm }}" + + # it takes a while to build the runtime, so let's save the artifact as soon as we have it + - name: Archive Artifacts for ${{ matrix.chain }} + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.chain }}-runtime + path: | + ${{ steps.srtool_build.outputs.wasm }} + ${{ steps.srtool_build.outputs.wasm_compressed }} + ${{ matrix.chain }}-srtool-digest.json + + # We now get extra information thanks to subwasm, + - name: Install subwasm ${{ env.SUBWASM_VERSION }} + run: | + wget https://github.com/chevdor/subwasm/releases/download/v${{ env.SUBWASM_VERSION }}/subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb + sudo dpkg -i subwasm_linux_amd64_v${{ env.SUBWASM_VERSION }}.deb + subwasm --version + - name: Show Runtime information + run: | + subwasm info ${{ steps.srtool_build.outputs.wasm }} + subwasm info ${{ steps.srtool_build.outputs.wasm_compressed }} + subwasm --json info ${{ steps.srtool_build.outputs.wasm }} > ${{ matrix.chain }}-info.json + subwasm --json info ${{ steps.srtool_build.outputs.wasm_compressed }} > ${{ matrix.chain }}-info_compressed.json + - name: Extract the metadata + run: | + subwasm meta ${{ steps.srtool_build.outputs.wasm }} + subwasm --json meta ${{ steps.srtool_build.outputs.wasm }} > ${{ matrix.chain }}-metadata.json + + - name: Archive Subwasm results + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.chain }}-runtime-${{ github.sha }} + path: | + ${{ matrix.chain }}-info.json + ${{ matrix.chain }}-info_compressed.json + ${{ matrix.chain }}-metadata.json + ${{ matrix.chain }}-diff.txt diff --git a/scripts/get_relevant_commit_of_runtime_since_last_tag.sh b/scripts/get_relevant_commit_of_runtime_since_last_tag.sh new file mode 100755 index 0000000000..a65529440e --- /dev/null +++ b/scripts/get_relevant_commit_of_runtime_since_last_tag.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +chosenRuntime="$1" +## forcefully set to lowercase +chosenRuntime=$( echo "$chosenRuntime" | tr -s '[:upper:]' '[:lower:]') + + +## list of runtimes available +runtimesList=("foucoco" "amplitude" "pendulum") + +excludeRuntimes='' +## will make comparison case-insensitive +for runtime in "${runtimesList[@]}"; do + ## exclude runtimes that is NOT chosen + if [[ "$runtime" != "$chosenRuntime" ]]; then + if [ -z "${excludeRuntimes}" ]; then + excludeRuntimes=$runtime + else + excludeRuntimes="$excludeRuntimes|$runtime" + fi + fi +done + +if [ -z "${excludeRuntimes}" ]; then + echo "unsupported runtime "$chosenRuntime + exit +fi + +## get the latest tag of this runtime +lastVersionName=$(git describe --abbrev=0 --tags --always `git rev-list --tags` | grep -i "$chosenRuntime*" -m 1) +echo "last version: "$lastVersionName + +## extract the version number of the version +lastVersionNumber=$(echo $lastVersionName | sed 's/[^0-9]*//g') +newVersionName=$chosenRuntime-release-$((lastVersionNumber+1)) +echo "new version: "$newVersionName +fileName="commits_for_"$newVersionName + +## remove the file if existed +if test -f $fileName; then + rm $fileName +fi + +## get the commits since the last tag +latestCommitOfLastVersion=$(git log $lastVersionName --oneline --max-count=1 | cut -c1-7) + +if [ -z "${latestCommitOfLastVersion}" ]; then + echo "last version is up to date." + exit +fi + +## only list commits related to this runtime and the general code changes +## save to file commits_for_-release-.txt +git log $latestCommitOfLastVersion..origin --oneline | grep -i -Ev "$excludeRuntimes" |cut -c1-7 >> $fileName + +