-
Notifications
You must be signed in to change notification settings - Fork 83
142 lines (127 loc) · 6.23 KB
/
update-replica-version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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"
sdkBranch:
description: 'Open PR against this sdk branch'
default: "master"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
IC_RELEASES_API: "https://ic-api.internetcomputer.org/api/v3/subnet-replica-versions?limit=50&offset=0"
# When getting Rust dependencies, retry on network error:
CARGO_NET_RETRY: 10
# Use the local .curlrc
CURL_HOME: .
jobs:
update-replica:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.sdkBranch }}
- 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@v21
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: install niv (dependency manager for Nix projects)
run: nix-env -i niv -f '<nixpkgs>'
- name: install packages from nix/sources.json
run: niv update
- name: update replica
run: |
echo "updating the replica"
scripts/update-replica.sh ${{ env.REPLICA_VERSION }}
- 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 }}-${{ github.event.inputs.sdkBranch }}
git add .
git commit -m "chore: update replica version to ${{ env.REPLICA_VERSION }}"
git push origin chore-update-replica-${{ env.REPLICA_VERSION }}-${{ github.event.inputs.sdkBranch }}
- name: create Pull Request, with CHANGELOG.md entry suggestion
uses: actions/github-script@v6
with:
github-token: ${{ secrets.NIV_UPDATER_TOKEN }} # act on behalf of https://github.com/dfinity-bot
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: <SHA>\" 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 }}-${{ github.event.inputs.sdkBranch }}',
base: '${{ github.event.inputs.sdkBranch }}',
body: [
`## Suggested [CHANGELOG.md](https://github.com/${owner}/${repo}/edit/chore-update-replica-${{ env.REPLICA_VERSION }}-${{ github.event.inputs.sdkBranch }}/CHANGELOG.md) changes`,
'```',
'## Dependencies',
'',
'### Replica',
'',
'Updated replica to elected commit ${{ env.REPLICA_VERSION }}.',
'This incorporates the following executed proposals:',
'',
new_proposals_since_last_release.map(el => `- [${el.proposal_id}](https://dashboard.internetcomputer.org/proposal/${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();