From beaace9324911d1f6f9c1d87734dacef57470bea Mon Sep 17 00:00:00 2001 From: Radhe Shyam Zeeve <98081359+radhe-zeeve@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:27:21 +0530 Subject: [PATCH] Add new Ink Version update support (#815) * add version update support Signed-off-by: Jasti Sri Radhe Shyam * add pipefail in ink version update, so that script failed on first error encounter Signed-off-by: Jasti Sri Radhe Shyam --------- Signed-off-by: Jasti Sri Radhe Shyam --- .github/workflows/ink_version_update.yml | 101 +++++++++++++++++++++++ Cargo.lock | 4 +- config/ink_versions.json | 6 ++ scripts/generate_ink_releases.sh | 7 ++ scripts/update_ink_version_to_latest.sh | 19 +++++ 5 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ink_version_update.yml create mode 100644 config/ink_versions.json create mode 100644 scripts/generate_ink_releases.sh create mode 100644 scripts/update_ink_version_to_latest.sh diff --git a/.github/workflows/ink_version_update.yml b/.github/workflows/ink_version_update.yml new file mode 100644 index 000000000..767983cd1 --- /dev/null +++ b/.github/workflows/ink_version_update.yml @@ -0,0 +1,101 @@ +name: Ink_Version_Update + +on: + workflow_dispatch: + schedule: + - cron: '0 6 * * *' + +jobs: + get_versions: + runs-on: ubuntu-latest + steps: + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + components: rustfmt + - name: Checkout + uses: actions/checkout@v3 + - name: Install jq + run: sudo apt -y install jq + - name: Fetch versions + run: bash ./scripts/generate_ink_releases.sh + - name: Show versions + run: cat ./config/ink_versions.json + - name: Generate versions variables and PR name + id: version_info + run: | + latest_ink_version=$(cat ./config/ink_versions.json | jq -r '.[0]') + echo "ink_version_changed=$(git diff --quiet -- ./config/ink_versions.json && echo 'false' || echo 'true')" >> $GITHUB_OUTPUT + echo "latest_ink_version=${latest_ink_version}" >> $GITHUB_OUTPUT + echo "ink_update_pr_name=[auto-generated] add new ink version: ${latest_ink_version}" >> $GITHUB_OUTPUT + - name: Update contract + if: ${{ steps.version_info.outputs.ink_version_changed == 'true' }} + run: bash ./scripts/update_ink_version_to_latest.sh + - name: Commit + if: ${{ steps.version_info.outputs.ink_version_changed == 'true' }} + run: | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git status + git add ./Cargo.lock + git add ./config/ink_versions.json + git add ./crates + git commit -m "update ink version list, latest version: ${{ steps.version_info.outputs.latest_ink_version }}" + - name: Duplicate PR check + uses: actions/github-script@v6 + with: + script: | + const prName = '${{ steps.version_info.outputs.ink_update_pr_name }}' + const otherPRs = await github.graphql(` + query { + repository(owner: "${{ github.repository_owner }}", name: "ink-playground") { + pullRequests(labels: ["INK_VERSION"], last: 100, states: [MERGED, OPEN]) { + edges { + node { + title + labels(first: 100) { + nodes { + name + } + } + } + } + } + } + } + `); + + console.log({otherPRs}) + + const otherPRsWithSameNameAndLabels = otherPRs.repository.pullRequests.edges.filter(edge => { + const otherPrName = edge.node.title; + return prName === otherPrName; + }); + + if (otherPRsWithSameNameAndLabels.length > 0) { + throw new Error('Open PR name and label must be unique'); + } + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: Update report + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false + branch: ink-version-${{ steps.version_info.outputs.latest_ink_version }} + delete-branch: true + title: ${{ steps.version_info.outputs.ink_update_pr_name }} + body: | + Update report + - Updated the Ink version to ${{ steps.version_info.outputs.latest_ink_version }} + - Auto-generated by [create-pull-request][1] + + [1]: https://github.com/peter-evans/create-pull-request + labels: | + INK_VERSION + github_actions + draft: false \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d5f98c970..d4e5fbb5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3500,9 +3500,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] diff --git a/config/ink_versions.json b/config/ink_versions.json new file mode 100644 index 000000000..77e39c313 --- /dev/null +++ b/config/ink_versions.json @@ -0,0 +1,6 @@ +[ + "4.2.0", + "4.1.0", + "4.0.1", + "4.0.0" +] diff --git a/scripts/generate_ink_releases.sh b/scripts/generate_ink_releases.sh new file mode 100644 index 000000000..5881b2397 --- /dev/null +++ b/scripts/generate_ink_releases.sh @@ -0,0 +1,7 @@ +relative_dirname="$(dirname -- "${BASH_SOURCE[0]}")" +bash_dir_path="$(cd -- "${relative_dirname}" && pwd)" +config_path=${bash_dir_path}/../config +ink_versions_list_path=${config_path}/ink_versions.json + +# This is provide stable version of Ink +curl -s https://crates.io/api/v1/crates/ink | jq '[ .versions[] | { num } | .num ] | map(select(. != "0.0.0")) | map(select(index("-") < 0))' > $ink_versions_list_path \ No newline at end of file diff --git a/scripts/update_ink_version_to_latest.sh b/scripts/update_ink_version_to_latest.sh new file mode 100644 index 000000000..18a10a5de --- /dev/null +++ b/scripts/update_ink_version_to_latest.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -eu +set -o pipefail + +relative_dirname="$(dirname -- "${BASH_SOURCE[0]}")" +bash_dir_path="$(cd -- "${relative_dirname}" && pwd)" + +config_path=${bash_dir_path}/../config +ink_versions_list_path=${config_path}/ink_versions.json + +contract_dir=${bash_dir_path}/../crates/contract +cd ${contract_dir} + +ink_latest_version=$(cat ${ink_versions_list_path} | jq -r '.[0]') +cargo install cargo-edit +cargo set-version --package contract "${ink_latest_version}" +cargo add --package contract ink@${ink_latest_version} +cargo add --package contract --dev ink_e2e@${ink_latest_version} \ No newline at end of file