Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
118 lines (96 loc) · 3.96 KB
/
Copy pathindex.js
File metadata and controls
118 lines (96 loc) · 3.96 KB
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
const core = require('@actions/core');
const exec = require('@actions/exec');
const { context } = require('@actions/github');
const axios = require('axios').default;
const github = require('@actions/github');
const fs = require('fs');
async function run() {
try {
const payload = context.payload;
const rpcAuthToken = core.getInput('rpcToken');
const githubToken = core.getInput('token');
core.setSecret(githubToken);
core.setSecret(rpcAuthToken);
const octokit = github.getOctokit(githubToken);
const [owner, repo] = payload.repository.full_name.split('/');
const artifactsResponse = await octokit.rest.actions.listArtifactsForRepo({
owner,
repo,
per_page: 50,
});
const artifacts = artifactsResponse.data.artifacts;
let artifactToDownload;
// Commits are ascending, but we need to check from latest -> oldest
const reversedCommits = payload.commits.reverse();
for (let commit of reversedCommits) {
const commitDiffArtifactName = `asset-${commit.id}-diff`;
const matchedArtifacts = artifacts.filter(artifact => artifact.name == commitDiffArtifactName);
if (matchedArtifacts.length) {
artifactToDownload = matchedArtifacts[0];
break;
}
}
if (!artifactToDownload) {
core.info('There is no build artifact belongs to commits of this push so no need to release.');
return;
}
await exec.exec(`git clone https://github.com/${payload.repository.full_name}.git .`);
const artifactDownloadResponse = await octokit.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifactToDownload.id,
archive_format: 'zip',
});
const artifactFilename = 'diff.zip';
await exec.exec(`wget -O ${artifactFilename} ${artifactDownloadResponse.url}`);
await exec.exec(`unzip ${artifactFilename}`);
await exec.exec(`git apply ${artifactToDownload.name}`);
await exec.exec(`rm ${artifactToDownload.name}`);
await exec.exec(`rm ${artifactFilename}`);
await exec.exec('git config user.name "github-actions[bot]"');
await exec.exec('git config user.email "github-actions[bot]@users.noreply.github.com"');
await exec.exec('git add .');
const manifest = JSON.parse(fs.readFileSync('./dappnode_package.json'));
const releases = JSON.parse(fs.readFileSync('./releases.json'));
const packageName = manifest.name;
const version = manifest.version;
const ipfsHash = releases[version].hash.replace('/ipfs/', '');
await exec.exec(`git commit --allow-empty -m "Release ${packageName} ${version}" -m "Manifest hash: ${ipfsHash}"`);
await exec.exec(`git push https://${process.env.GITHUB_ACTOR}:${githubToken}@github.com/${payload.repository.full_name}.git`);
await axios.post(
'https://adminrpc.ava.do',
{
jsonrpc: '2.0',
id: 1,
method: 'store.setPackageHash',
params: {
name: packageName,
ipfsHash: ipfsHash,
},
},
{
headers: {
Authorization: `${rpcAuthToken}`,
}
}
);
// Straight to adminrpc: bo.ava.do/rpc only proxied this call to it,
// and bo.ava.do's backend (bo2) went down on 2026-10-20.
await axios.post(
'https://adminrpc.ava.do',
{
jsonrpc: '2.0',
id: 1,
method: 'store.releaseStore',
},
{
headers: {
Authorization: `${rpcAuthToken}`,
}
}
);
} catch (error) {
core.setFailed(error.message);
}
}
run();