-
-
Notifications
You must be signed in to change notification settings - Fork 25
Cache activity before opening retirement PRs #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philiptaron
wants to merge
1
commit into
NixOS:main
Choose a base branch
from
philiptaron:issue-100
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| .tmp | ||
| .cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Restores the activity cache artifact uploaded by the previous successful | ||
| // run of the retire workflow, for use by scripts/retire.js. | ||
| // Runs in CI via actions/github-script (see .github/workflows/retire.yml). | ||
| // | ||
| // Any failure here only means starting without a cache, which is safe: | ||
| // a missing cache can delay retirements, but never cause one. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const { execFileSync } = require('child_process'); | ||
|
|
||
| module.exports = async function restoreCache({ github, context, core, artifactName, dir }) { | ||
| const { owner, repo } = context.repo; | ||
| try { | ||
| const runs = ( | ||
| await github.request(`GET /repos/${owner}/${repo}/actions/workflows/retire.yml/runs`, { | ||
| status: 'success', | ||
| per_page: 1, | ||
| }) | ||
| ).data.workflow_runs; | ||
| if (runs.length === 0) { | ||
| core.info('No previous successful run, starting fresh'); | ||
| return; | ||
| } | ||
| const runId = runs[0].id; | ||
|
|
||
| const artifacts = ( | ||
| await github.request(`GET /repos/${owner}/${repo}/actions/runs/${runId}/artifacts`) | ||
| ).data.artifacts; | ||
| const artifact = artifacts.find((a) => a.name === artifactName && !a.expired); | ||
| if (!artifact) { | ||
| core.warning(`Run ${runId} has no ${artifactName} artifact, starting fresh`); | ||
| return; | ||
| } | ||
|
|
||
| // The artifact download endpoint always serves a zip archive | ||
| const zip = ( | ||
| await github.request(`GET /repos/${owner}/${repo}/actions/artifacts/${artifact.id}/zip`) | ||
| ).data; | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| const zipPath = path.join(dir, `${artifactName}.zip`); | ||
| fs.writeFileSync(zipPath, Buffer.from(zip)); | ||
| execFileSync('unzip', ['-o', zipPath, '-d', dir], { stdio: 'inherit' }); | ||
| fs.rmSync(zipPath); | ||
| core.info(`Restored activity cache from run ${runId}`); | ||
| } catch (err) { | ||
| core.warning(`Could not restore activity cache, starting fresh: ${err.message}`); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env node | ||
| // Local runner for scripts/retire.js, providing an Octokit-compatible shim | ||
| // backed by the `gh` CLI so no npm dependencies are needed. | ||
| // See scripts/README.md for the test sequence. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const { execFileSync } = require('child_process'); | ||
| const retire = require('./retire.js'); | ||
|
|
||
| function usage() { | ||
| console.error(`Usage: ${process.argv[1]} ORG ACTIVITY_REPO MEMBER_REPO DIR NOTICE_CUTOFF CLOSE_CUTOFF CONFIRM_CUTOFF`); | ||
| console.error(''); | ||
| console.error('Optionally set CACHE_FILE to a path for persisting activity observations between runs.'); | ||
| console.error('Set PROD=1 to actually perform side effects.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const [org, activityRepo, memberRepo, dir, noticeCutoffSpec, closeCutoffSpec, confirmCutoffSpec] = | ||
| process.argv.slice(2); | ||
| if (!confirmCutoffSpec) { | ||
| usage(); | ||
| } | ||
|
|
||
| function gh(args, input) { | ||
| return execFileSync('gh', args, { | ||
| input, | ||
| encoding: 'utf8', | ||
| maxBuffer: 64 * 1024 * 1024, | ||
| }); | ||
| } | ||
|
|
||
| const github = { | ||
| async request(route, params = {}) { | ||
| const [method, pathTemplate] = route.split(' '); | ||
| let args; | ||
| let input; | ||
| if (method === 'GET') { | ||
| const query = new URLSearchParams(params).toString(); | ||
| args = ['api', '-X', 'GET', query ? `${pathTemplate}?${query}` : pathTemplate]; | ||
| } else { | ||
| args = ['api', '-X', method, pathTemplate, '--input', '-']; | ||
| input = JSON.stringify(params); | ||
| } | ||
| const out = gh(args, input); | ||
| return { data: out.trim() === '' ? null : JSON.parse(out) }; | ||
| }, | ||
| async graphql(query, variables = {}) { | ||
| const out = gh(['api', 'graphql', '--input', '-'], JSON.stringify({ query, variables })); | ||
| const parsed = JSON.parse(out); | ||
| if (parsed.errors) { | ||
| throw new Error(JSON.stringify(parsed.errors)); | ||
| } | ||
| return parsed.data; | ||
| }, | ||
| }; | ||
|
|
||
| retire({ | ||
| github, | ||
| options: { | ||
| org, | ||
| activityRepo, | ||
| memberRepo, | ||
| dir, | ||
| noticeCutoffSpec, | ||
| closeCutoffSpec, | ||
| confirmCutoffSpec, | ||
| cacheFile: process.env.CACHE_FILE, | ||
| prod: Boolean(process.env.PROD), | ||
| }, | ||
| }).catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.