Skip to content
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

Use GitHub Actions to autoupdate to latest nightly build #1

Merged
merged 2 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
on:
push:
branches: [main]
schedule:
- cron: '0 6 * * *'

jobs:
update-nightly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/github-script@v5
with:
script: |
const fs = require("fs").promises;
const crypto = require("crypto");
const https = require("https");

const [owner, repo] = ["crystal-lang", "crystal"];

const {data: {workflow_runs}} = await github.rest.actions.listWorkflowRuns({
owner, repo, workflow_id: "win.yml", branch: "master", event: "push", status: "success", per_page: 1,
});
if (!workflow_runs.length) {
return core.error("No workflow runs found");
}
const [{id: run_id, head_sha}] = workflow_runs;

const {data: {artifacts}} = await github.rest.actions.listWorkflowRunArtifacts({
owner, repo, run_id,
});
const artifact = artifacts.find((x) => x.name === "crystal");
if (!artifact) {
return core.error("No 'crystal' artifact found");
}

const urls = [
`https://github.com/crystal-lang/crystal/archive/${head_sha}.zip`,
`https://nightly.link/crystal-lang/crystal/actions/artifacts/${artifact.id}.zip`,
];
const hashes = await Promise.all(urls.map(hash_url));

function hash_url(url) {
return new Promise((resolve, reject) => {
https.get(url, (response) => {
const hash = crypto.createHash("sha256");
response.on("error", reject);
response.on("data", (chunk) => hash.update(chunk));
response.on("end", () => resolve(hash.digest("hex").toUpperCase()));
});
});
}

const data = JSON.parse(await fs.readFile("bucket/crystal.json", "utf8"));

data["description"] = `Crystal programming language preview @ ${head_sha.slice(0, 9)}`;
data["pre_install"] = [`mv $dir\\crystal-${head_sha} $dir\\crystal-lang`];
data["url"] = urls.concat(data["url"].slice(2));
data["hash"] = hashes.concat(data["hash"].slice(2));

await fs.writeFile("bucket/crystal.json", JSON.stringify(data, null, 4) + "\n", "utf8");

- run: git diff --exit-code || git -c user.email='github-actions[bot]@users.noreply.github.com' -c user.name='github-actions[bot]' commit -a -m 'Update nightly version'
- run: git push
29 changes: 0 additions & 29 deletions bucket/crystal-nightly.json

This file was deleted.

22 changes: 15 additions & 7 deletions bucket/crystal.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"version": "1.2.2",
"description" : "Crystal programming language preview @ 90218d9",
"description": "Crystal programming language preview @ 90218d9fc",
"homepage": "https://crystal-lang.org/",
"license": {
"identifier": "Freeware",
"url": "https://github.com/crystal-lang/crystal/blob/master/LICENSE"
},
"pre_install" : ["mv $dir\\crystal-90218d9fc0a2cd06272b659371504ad543add1f4 $dir\\crystal-lang"],
"pre_install": [
"mv $dir\\crystal-90218d9fc0a2cd06272b659371504ad543add1f4 $dir\\crystal-lang"
],
"url": [
"https://github.com/crystal-lang/crystal/archive/90218d9fc0a2cd06272b659371504ad543add1f4.zip",
"https://nightly.link/crystal-lang/crystal/actions/artifacts/118295502.zip",
Expand All @@ -17,8 +19,11 @@
"B987CC1E951EBF70C6CD2D74F444118A9F9737119B8934B16AD271EBDEB777E3",
"2F35032B2F12AE8F7E8EF37FF95F1D6404035E42631555923B7C30CDBC1653B4"
],
"depends": ["vswhere", "git"],
"extract_to" : [
"depends": [
"vswhere",
"git"
],
"extract_to": [
"",
"lib",
""
Expand All @@ -28,8 +33,11 @@
"LIB": "$dir\\lib",
"CRYSTAL_PATH": "$dir;$dir\\crystal-lang\\src"
},
"bin": ["crystal.ps1"],
"post_install": [
"bin": [
"crystal.ps1"
],
"post_install": [
"mv $dir\\lib\\crystal.exe $dir\\_crystal.exe",
"If (Test-Path $env:LOCALAPPDATA\\crystal\\cache) { rm -r -fo $env:LOCALAPPDATA\\crystal\\cache}"]
"If (Test-Path $env:LOCALAPPDATA\\crystal\\cache) { rm -r -fo $env:LOCALAPPDATA\\crystal\\cache}"
]
}
67 changes: 0 additions & 67 deletions scripts/grab_latest_nightly.ps1

This file was deleted.