-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f203a0
commit 88d325e
Showing
20 changed files
with
1,500 additions
and
524 deletions.
There are no files selected for viewing
This file contains 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,27 +1,35 @@ | ||
name: Run Archive | ||
name: Archive | ||
|
||
on: | ||
# once a month | ||
# run once a month | ||
schedule: | ||
- cron: "0 0 1 * *" | ||
# on demand | ||
# run on manual trigger | ||
workflow_dispatch: | ||
|
||
env: | ||
FORCE_COLOR: true | ||
GITHUB_USER: "${{ secrets.GITHUB_USER }}" | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
SOFTWARE_HERITAGE_TOKEN: "${{ secrets.SOFTWARE_HERITAGE_TOKEN }}" | ||
|
||
jobs: | ||
run-bot: | ||
archive: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
# secrets to environment variables | ||
environment: backup | ||
env: | ||
SOFTWARE_HERITAGE_TOKEN: ${{ secrets.SOFTWARE_HERITAGE_TOKEN }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node | ||
uses: actions/setup-node@v1 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "12.x" | ||
node-version: "18" | ||
|
||
- name: Install packages | ||
run: yarn install | ||
run: npm install | ||
|
||
- name: Run archive | ||
run: yarn archive | ||
run: npm run archive | ||
timeout-minutes: 60 |
This file contains 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,4 +1,2 @@ | ||
node_modules | ||
.env | ||
clone | ||
clone.sh |
This file contains 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,4 @@ | ||
{ | ||
"plugins": ["@ianvs/prettier-plugin-sort-imports"], | ||
"importOrder": ["^[a-zA-Z]", "^@[a-zA-Z]", "^./"] | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,10 @@ | ||
import { getRepos } from "./github"; | ||
import { archiveRepos } from "./software-heritage"; | ||
|
||
/** archive script */ | ||
const archive = async () => { | ||
const repos = await getRepos(); | ||
await archiveRepos(repos); | ||
}; | ||
|
||
archive(); |
This file contains 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,24 @@ | ||
import { execSync } from "child_process"; | ||
import { githubUser } from "./env"; | ||
import { getRepos } from "./github"; | ||
import { info } from "./util"; | ||
|
||
/** clone directory */ | ||
const dir = `../${githubUser}-clone`; | ||
|
||
/** clone repos locally */ | ||
const cloneRepos = async (urls: string[]) => { | ||
info(`Cloning repos to ${dir}`); | ||
|
||
/** run commands to clone */ | ||
execSync(`mkdir -p ${dir}`); | ||
for (const url of urls) execSync(`git clone ${url}`, { cwd: dir }); | ||
}; | ||
|
||
/** clone script */ | ||
const clone = async () => { | ||
const repos = await getRepos(); | ||
await cloneRepos(repos); | ||
}; | ||
|
||
clone(); |
This file contains 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,30 @@ | ||
import { info } from "./util"; | ||
|
||
/** load env vars from local .env file */ | ||
require("dotenv").config(); | ||
|
||
/** github user or organization name, e.g. "greenelab" */ | ||
const githubUser = | ||
/** read from explicitly set env var */ | ||
process.env.GITHUB_USER || | ||
/** or, read from env var set by github actions */ | ||
(process.env.GITHUB_REPOSITORY || "").split("/")[0] || | ||
""; | ||
|
||
/** github auth token */ | ||
const githubToken = process.env.GITHUB_TOKEN || ""; | ||
/** software heritage auth/api token */ | ||
const softwareHeritageToken = process.env.SOFTWARE_HERITAGE_TOKEN || ""; | ||
|
||
/** log key */ | ||
const logKey = (name = "", value = "", truncate = true) => | ||
info( | ||
`${name}: ${truncate && value ? `"...${value.slice(-4)}"` : `"${value}"`}`, | ||
); | ||
|
||
/** log keys */ | ||
logKey("GITHUB_USER", githubUser, false); | ||
logKey("GITHUB_TOKEN", githubToken); | ||
logKey("SOFTWARE_HERITAGE_TOKEN", softwareHeritageToken); | ||
|
||
export { githubUser, githubToken, softwareHeritageToken }; |
Oops, something went wrong.