-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
178 lines (155 loc) · 6.23 KB
/
action.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: "NMS Deployment"
description: "Deploying various nms versions to the local maven repository"
inputs:
versions:
description: "The versions of the NMS to deploy, split by newline"
required: true
access-token:
description: "The GitHub PAT to use for referencing the NMS repository"
required: true
nms-repository:
description: "The repository that contains the prebuilt NMS artifacts."
required: true
default: "TeamKun/NMSBuilds"
deploy-path:
description: "The path to deploy the NMS to"
required: true
default: "~/.m2/repository"
branding:
icon: "package"
color: "blue"
author: "PeyaPeyaPeyang"
runs:
using: composite
steps:
- name: Create temporary directory
run: mkdir -p temp
shell: bash
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install node-fetch
run: npm install node-fetch
shell: bash
- name: Collect NMS artifacts
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const { pipeline } = require('stream');
const versions = process.env.VERSIONS.split("\n")
.filter(version => version.trim().length > 0)
.map(version => "nms-" + version)
.map(version => version.replace(/#.*/, "").trim());
const token = process.env.GH_TOKEN;
const tempPath = "temp";
const repository = process.env.REPOSITORY;
const repositoryOwner = repository.split("/")[0];
const repositoryName = repository.split("/")[1];
const query = `
query($repoOwner: String!, $repoName: String!) {
repository(owner: $repoOwner, name: $repoName) {
releases(first: 100) {
edges {
node {
tagName
releaseAssets(first: 1, name: "m2.tar.gz") {
edges {
node {
url
}
}
}
}
}
}
}
}
`;
const url = `https://api.github.com/graphql`;
async function downloadArtifact(assetUrl, assetName) {
console.log(`Downloading NMS artifact from ${assetUrl}...`);
const response = await fetch(assetUrl, {
headers: {
"Accept": "application/octet-stream",
}
});
if (!response.ok) {
throw new Error(`Failed to download NMS artifact from ${assetUrl}`);
}
console.log(`Writing NMS artifact to ${assetName}...`);
const dest = fs.createWriteStream(assetName);
await new Promise((resolve, reject) => {
pipeline(response.body, dest, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
console.log(`Successfully wrote NMS artifact to ${assetName}.`);
}
async function fetchArtifacts() {
try {
console.log("Fetching NMS artifacts...");
console.log(` Using token: ${token.length} characters, starting with ${token.substring(0, 5)}`);
const res = await fetch(url, {
method: 'POST',
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
query: query,
variables: {
repoOwner: repositoryOwner,
repoName: repositoryName
}
})
});
const data = await res.json();
if (!data.data || !data.data.repository || !data.data.repository.releases) {
console.error("Failed to fetch NMS artifacts:");
console.error(data);
throw new Error("Failed to fetch NMS artifacts");
}
const releases = data.data.repository.releases.edges;
const foundVersions = [];
for (const release of releases) {
const tagName = release.node.tagName;
if (versions.includes(tagName)) {
console.log(`Found NMS artifact for version ${tagName}`);
foundVersions.push(tagName);
const asset = release.node.releaseAssets.edges[0].node;
const assetUrl = asset.url;
const assetName = path.join(tempPath, `${tagName}.tar.gz`);
await downloadArtifact(assetUrl, assetName);
await new Promise(resolve => setTimeout(resolve, 1000)); // 1000ms間隔
}
}
if (foundVersions.length === versions.length) {
return;
}
console.error("Failed to find NMS artifacts for " + versions.filter(version => !foundVersions.includes(version)).join(", "));
} catch (err) {
console.error(err);
process.exit(1);
}
}
fetchArtifacts();
env:
GH_TOKEN: ${{ inputs.access-token }}
REPOSITORY: ${{ inputs.nms-repository }}
VERSIONS: ${{ inputs.versions }}
- name: Extract, merge and deploy NMS artifacts
run: |
mkdir -p ${{ inputs.deploy-path }}
for file in temp/*.tar.gz; do
echo "Extracting $file..."
tar -xzf $file -C ${{ inputs.deploy-path }}
done
shell: bash
# Done