diff --git a/.github/CONTRIBUTING.adoc b/.github/CONTRIBUTING.adoc index 4c16f0506d..3e779e2e04 100644 --- a/.github/CONTRIBUTING.adoc +++ b/.github/CONTRIBUTING.adoc @@ -87,6 +87,14 @@ What that means is your PR title should start with one of the following prefix: === Updating the Replica +==== Using GitHub Action +. Head over to https://github.com/dfinity/sdk/actions/workflows/update-replica-version.yml[the GitHub Action]. +. Click "Run workflow" button, choose appropriate options (you're probably fine with using defaults), and click "Run workflow" (the green one). +. Depending on the selected options, the workflow will run anything between 3 to 35 minutes. After that time, a new PR will be created. +. The PR contains the content that needs to be pasted into CHANGELOG.adoc, as well as the link for editing the CHANGELOG.adoc directly on the branch of that PR. +. After making changes to the CHANGELOG.adoc file, PR is ready for review. + +==== Locally To update the replica to a given $SHA from the dfinity repo, execute the following: [source,bash] ---- @@ -101,6 +109,8 @@ To update Motoko to a given $VERSION from the motoko and motoko-base repos, exec ---- # Requires niv to run. To install niv, run nix-env -iA nixpkgs.niv ./scripts/update-motoko.sh $VERSION +# if you want to also update ledger canisters for e2e tests, use: +./scripts/update-motoko.sh $VERSION --update-nns ---- === Licenses diff --git a/.github/workflows/update-replica-version.yml b/.github/workflows/update-replica-version.yml new file mode 100644 index 0000000000..6e276d4aa5 --- /dev/null +++ b/.github/workflows/update-replica-version.yml @@ -0,0 +1,136 @@ +name: "chore: Update replica" +on: + workflow_dispatch: + inputs: + replicaVersionLatestOrCustom: + description: 'use latest replica version, or provide custom revision' + type: choice + default: 'latest' + options: + - latest + - custom + customReplicaVersion: + description: 'dfinity/ic commit SHA - get the latest Elect Replica Version from https://dashboard.internetcomputer.org/releases' + default: "required if custom" + updateNnsCanisters: + description: 'Update the NNS canisters for e2e tests' + type: boolean + default: true +env: + IC_RELEASES_API: "https://ic-api.internetcomputer.org/api/v3/subnet-replica-versions?limit=50&offset=0" + +jobs: + update-replica: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.0.2 + + - name: determine replica commit sha + run: | + if [ '${{ github.event.inputs.replicaVersionLatestOrCustom }}' = 'latest' ]; then + echo "REPLICA_VERSION=$(curl -s "${{ env.IC_RELEASES_API }}" | jq -r '.data[0].replica_version_id')" >> $GITHUB_ENV + else + echo "REPLICA_VERSION=${{ github.event.inputs.customReplicaVersion }}" >> $GITHUB_ENV + fi + grep -s "REPLICA_VERSION" $GITHUB_ENV + + - name: install Nix + uses: cachix/install-nix-action@d64e0553100205688c0fb2fa16edb0fc8663c590 # https://github.com/cachix/install-nix-action/releases/tag/v17 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - name: install niv (dependency manager for Nix projects) + run: nix-env -i niv -f '' + + - name: intall packages from nix/sources.json + run: niv update + + - name: update replica + run: | + if [ ${{ github.event.inputs.updateNnsCanisters }} = true ]; then + echo "updating the replica and NNS canisters for e2e test" + scripts/update-replica.sh ${{ env.REPLICA_VERSION }} --update-nns + else + echo "updating the replica" + scripts/update-replica.sh ${{ env.REPLICA_VERSION }} + fi + + - name: setup git config, then create new branch and push new commit to it + run: | + git config author.email "${{ github.event.sender.id }}+${{ github.event.sender.login }}@users.noreply.github.com" + git config author.name "${{ github.event.sender.login }}" + git config committer.email "41898282+github-actions[bot]@users.noreply.github.com" + git config committer.name "GitHub Actions Bot" + git config user.email "${{ github.event.sender.id }}+${{ github.event.sender.login }}@users.noreply.github.com" + git config user.name "${{ github.event.sender.login }}" + git checkout -b chore-update-replica-${{ env.REPLICA_VERSION }} + git add . + git commit -m "chore: update replica version to ${{ env.REPLICA_VERSION }}" + git push origin chore-update-replica-${{ env.REPLICA_VERSION }} + + - name: create Pull Request, with CHANGELOG.adoc entry suggestion + uses: actions/github-script@v6 + with: + script: | + const { repo, owner } = context.repo; + + let latest_dfx_release = await github.rest.repos.getLatestRelease({ owner, repo }); + core.startGroup('latest dfx release'); + core.info(JSON.stringify(latest_dfx_release, null, 2)); + core.endGroup(); + + const re = /replica version used: ([a-f0-9]+)/g; + let latest_release_replica_version; + try { + latest_release_replica_version = re.exec(latest_dfx_release.data.body)[1]; + core.info(`latest_release_replica_version = ${latest_release_replica_version}`); + } catch { + latest_release_replica_version = ""; + core.warning("the phrase \"replica version used: \" has not been found in latest GitHub Release"); + } + + let elected_replicas = await github.request("GET ${{ env.IC_RELEASES_API }}"); + core.startGroup('elected_replicas fetched from ic-api.internetcomputer.org'); + core.info(JSON.stringify(elected_replicas, null, 2)); + core.endGroup(); + + let idx_start = elected_replicas.data.data.findIndex(el => el.replica_version_id === "${{ env.REPLICA_VERSION }}"); + let idx_end = elected_replicas.data.data.findIndex(el => el.replica_version_id === latest_release_replica_version); + core.info(`idx_start:idx_end is ${idx_start}:${idx_end}`); + let new_proposals_since_last_release = elected_replicas.data.data.slice(idx_start, idx_end); + core.startGroup('new proposals since last release'); + core.info(JSON.stringify(new_proposals_since_last_release, null, 2)); + core.endGroup(); + + const new_replica_sha__short = "${{ env.REPLICA_VERSION }}".substring(0, 8); + const pr_create_result = await github.rest.pulls.create({ + title: `chore: update replica version to ${new_replica_sha__short}`, + owner, + repo, + head: 'chore-update-replica-${{ env.REPLICA_VERSION }}', + base: 'master', + body: [ + `## Suggested [CHANGELOG.adoc](https://github.com/${owner}/${repo}/edit/chore-update-replica-${{ env.REPLICA_VERSION }}/CHANGELOG.adoc) changes`, + '```', + '== Dependencies', + '', + '=== Replica', + '', + 'Updated replica to elected commit ${{ env.REPLICA_VERSION }}.', + 'This incorporates the following executed proposals:', + '', + new_proposals_since_last_release.map(el => `* https://dashboard.internetcomputer.org/proposal/${el.proposal_id}[${el.proposal_id}]`).join('\n'), + '```', + '## Previous replica version', + `\`${latest_release_replica_version}\`` + ].join('\n') + }); + github.rest.issues.addLabels({ + owner, + repo, + issue_number: pr_create_result.data.number, + labels: ['chore', 'automerge-squash'] + }); + core.startGroup('new PR JSON object'); + core.info(JSON.stringify(pr_create_result, null, 2)); + core.endGroup(); \ No newline at end of file diff --git a/scripts/update-replica.sh b/scripts/update-replica.sh index 68b5dae7a8..7b64bfaf6e 100755 --- a/scripts/update-replica.sh +++ b/scripts/update-replica.sh @@ -26,9 +26,10 @@ niv update sandbox-launcher-x86_64-linux -a rev=$SHA echo "Writing asset sources" ./scripts/write-dfx-asset-sources.sh -read -r -p "Update the ledger for e2e tests? (y/n)" yn -if [[ ! $yn =~ [nN] ]]; then - ./scripts/update-nns.bash "$SHA" -fi +for arg in "$@"; do + if [ "$arg" = '--update-nns' ]; then + ./scripts/update-nns.bash "$SHA" + fi +done echo "Done. Don't forget to update CHANGELOG.adoc"