mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #11103
11103: internal: Improve `github-release` action r=lnicola a=lnicola Upgrade ``@actions/github`` to get `listReleaseAssets` and retry individual uploads in addition to the whole thing. Also disables `ci`, `metrics` and `rustdoc` on forks to save some CPU time. CC #11056 Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
4ea1f58bf6
6 changed files with 64 additions and 39 deletions
86
.github/actions/github-release/main.js
vendored
86
.github/actions/github-release/main.js
vendored
|
@ -5,7 +5,7 @@ const github = require('@actions/github');
|
|||
const glob = require('glob');
|
||||
|
||||
function sleep(milliseconds) {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
||||
async function runOnce() {
|
||||
|
@ -20,9 +20,8 @@ async function runOnce() {
|
|||
|
||||
core.info(`files: ${files}`);
|
||||
core.info(`name: ${name}`);
|
||||
core.info(`token: ${token}`);
|
||||
|
||||
const octokit = new github.GitHub(token);
|
||||
const octokit = github.getOctokit(token);
|
||||
|
||||
// Delete the previous release since we can't overwrite one. This may happen
|
||||
// due to retrying an upload or it may happen because we're doing the dev
|
||||
|
@ -34,24 +33,24 @@ async function runOnce() {
|
|||
}
|
||||
const release_id = release.id;
|
||||
core.info(`deleting release ${release_id}`);
|
||||
await octokit.repos.deleteRelease({ owner, repo, release_id });
|
||||
await octokit.rest.repos.deleteRelease({ owner, repo, release_id });
|
||||
}
|
||||
|
||||
// We also need to update the `dev` tag while we're at it on the `dev` branch.
|
||||
if (name == 'nightly') {
|
||||
try {
|
||||
core.info(`updating nightly tag`);
|
||||
await octokit.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: 'tags/nightly',
|
||||
sha,
|
||||
force: true,
|
||||
await octokit.rest.git.updateRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: 'tags/nightly',
|
||||
sha,
|
||||
force: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("ERROR: ", JSON.stringify(e, null, 2));
|
||||
core.error(e);
|
||||
core.info(`creating nightly tag`);
|
||||
await octokit.git.createTag({
|
||||
await octokit.rest.git.createTag({
|
||||
owner,
|
||||
repo,
|
||||
tag: 'nightly',
|
||||
|
@ -65,7 +64,7 @@ async function runOnce() {
|
|||
// Creates an official GitHub release for this `tag`, and if this is `dev`
|
||||
// then we know that from the previous block this should be a fresh release.
|
||||
core.info(`creating a release`);
|
||||
const release = await octokit.repos.createRelease({
|
||||
const release = await octokit.rest.repos.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
name,
|
||||
|
@ -73,47 +72,68 @@ async function runOnce() {
|
|||
target_commitish: sha,
|
||||
prerelease: name === 'nightly',
|
||||
});
|
||||
const release_id = release.data.id;
|
||||
|
||||
// Upload all the relevant assets for this release as just general blobs.
|
||||
for (const file of glob.sync(files)) {
|
||||
const size = fs.statSync(file).size;
|
||||
core.info(`upload ${file}`);
|
||||
await octokit.repos.uploadReleaseAsset({
|
||||
data: fs.createReadStream(file),
|
||||
headers: { 'content-length': size, 'content-type': 'application/octet-stream' },
|
||||
name: path.basename(file),
|
||||
url: release.data.upload_url,
|
||||
const name = path.basename(file);
|
||||
|
||||
await runWithRetry(async function () {
|
||||
// We can't overwrite assets, so remove existing ones from a previous try.
|
||||
let assets = await octokit.rest.repos.listReleaseAssets({
|
||||
owner,
|
||||
repo,
|
||||
release_id
|
||||
});
|
||||
for (const asset of assets.data) {
|
||||
if (asset.name === name) {
|
||||
core.info(`delete asset ${name}`);
|
||||
const asset_id = asset.id;
|
||||
await octokit.rest.repos.deleteReleaseAsset({ owner, repo, asset_id });
|
||||
}
|
||||
}
|
||||
|
||||
core.info(`upload ${file}`);
|
||||
const headers = { 'content-length': size, 'content-type': 'application/octet-stream' };
|
||||
const data = fs.createReadStream(file);
|
||||
await octokit.rest.repos.uploadReleaseAsset({
|
||||
data,
|
||||
headers,
|
||||
name,
|
||||
url: release.data.upload_url,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
async function runWithRetry(f) {
|
||||
const retries = 10;
|
||||
const maxDelay = 4000;
|
||||
let delay = 1000;
|
||||
|
||||
for (let i = 0; i < retries; i++) {
|
||||
try {
|
||||
await runOnce();
|
||||
await f();
|
||||
break;
|
||||
} catch (e) {
|
||||
if (i === retries - 1)
|
||||
throw e;
|
||||
logError(e);
|
||||
console.log("RETRYING after 10s");
|
||||
await sleep(10000)
|
||||
|
||||
core.error(e);
|
||||
const currentDelay = Math.round(Math.random() * delay);
|
||||
core.info(`sleeping ${currentDelay} ms`);
|
||||
await sleep(currentDelay);
|
||||
delay = Math.min(delay * 2, maxDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logError(e) {
|
||||
console.log("ERROR: ", e.message);
|
||||
try {
|
||||
console.log(JSON.stringify(e, null, 2));
|
||||
} catch (e) {
|
||||
// ignore json errors for now
|
||||
}
|
||||
console.log(e.stack);
|
||||
async function run() {
|
||||
await runWithRetry(runOnce);
|
||||
}
|
||||
|
||||
run().catch(err => {
|
||||
logError(err);
|
||||
core.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
|
|
4
.github/actions/github-release/package.json
vendored
4
.github/actions/github-release/package.json
vendored
|
@ -3,8 +3,8 @@
|
|||
"version": "0.0.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.0.0",
|
||||
"@actions/github": "^1.0.0",
|
||||
"@actions/core": "^1.6",
|
||||
"@actions/github": "^5.0",
|
||||
"glob": "^7.1.5"
|
||||
}
|
||||
}
|
||||
|
|
3
.github/workflows/ci.yaml
vendored
3
.github/workflows/ci.yaml
vendored
|
@ -17,6 +17,7 @@ env:
|
|||
|
||||
jobs:
|
||||
rust:
|
||||
if: github.repository == 'rust-analyzer/rust-analyzer'
|
||||
name: Rust
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
|
@ -61,6 +62,7 @@ jobs:
|
|||
|
||||
# Weird targets to catch non-portable code
|
||||
rust-cross:
|
||||
if: github.repository == 'rust-analyzer/rust-analyzer'
|
||||
name: Rust Cross
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
@ -97,6 +99,7 @@ jobs:
|
|||
done
|
||||
|
||||
typescript:
|
||||
if: github.repository == 'rust-analyzer/rust-analyzer'
|
||||
name: TypeScript
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
|
1
.github/workflows/metrics.yaml
vendored
1
.github/workflows/metrics.yaml
vendored
|
@ -12,6 +12,7 @@ env:
|
|||
|
||||
jobs:
|
||||
metrics:
|
||||
if: github.repository == 'rust-analyzer/rust-analyzer'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
|
8
.github/workflows/release.yaml
vendored
8
.github/workflows/release.yaml
vendored
|
@ -162,12 +162,12 @@ jobs:
|
|||
- run: npm ci
|
||||
working-directory: editors/code
|
||||
|
||||
- name: Publish Extension (release)
|
||||
- name: Package Extension (release)
|
||||
if: github.ref == 'refs/heads/release'
|
||||
run: npx vsce package -o "../../dist/rust-analyzer-alpine-x64.vsix" --target alpine-x64
|
||||
working-directory: editors/code
|
||||
|
||||
- name: Publish Extension (nightly)
|
||||
- name: Package Extension (nightly)
|
||||
if: github.ref != 'refs/heads/release'
|
||||
run: npx vsce package -o "../../dist/rust-analyzer-alpine-x64.vsix" --target alpine-x64 --pre-release
|
||||
working-directory: editors/code
|
||||
|
@ -247,12 +247,12 @@ jobs:
|
|||
working-directory: ./editors/code
|
||||
|
||||
- name: Publish Extension (release)
|
||||
if: github.ref == 'refs/heads/release'
|
||||
if: github.ref == 'refs/heads/release' && github.repository == 'rust-analyzer/rust-analyzer'
|
||||
working-directory: ./editors/code
|
||||
# token from https://dev.azure.com/rust-analyzer/
|
||||
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer-*.vsix
|
||||
|
||||
- name: Publish Extension (nightly)
|
||||
if: github.ref != 'refs/heads/release'
|
||||
if: github.ref != 'refs/heads/release' && github.repository == 'rust-analyzer/rust-analyzer'
|
||||
working-directory: ./editors/code
|
||||
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer-*.vsix --pre-release
|
||||
|
|
1
.github/workflows/rustdoc.yaml
vendored
1
.github/workflows/rustdoc.yaml
vendored
|
@ -12,6 +12,7 @@ env:
|
|||
|
||||
jobs:
|
||||
rustdoc:
|
||||
if: github.repository == 'rust-analyzer/rust-analyzer'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
|
Loading…
Reference in a new issue