Do not change default version on known checksum update (#39)

This commit is contained in:
Kevin Stillhammer 2024-09-05 15:26:17 +02:00 committed by GitHub
parent bfebbf80cb
commit b3cf8231d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 34804 additions and 101 deletions

View File

@ -19,7 +19,7 @@ categories:
labels:
- "maintenance"
- "ci"
- "default-version-update"
- "update-known-checksums"
- title: "📚 Documentation"
labels:
- "documentation"

View File

@ -1,33 +0,0 @@
name: "Update default version and checksums"
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Update default version and checksums
id: update-default-version
run:
node dist/update-default-version/index.js
src/download/checksum/known-checksums.ts action.yml ${{
secrets.GITHUB_TOKEN }}
- run: npm install && npm run all
- name: Create Pull Request
uses: peter-evans/create-pull-request@8867c4aba1b742c39f8d0ba35429c2dfa4b6cb20 # v7.0.1
with:
commit-message: "chore: update checksums"
title:
"chore: update default version to ${{
steps.update-default-version.outputs.latest-version }}"
body:
"chore: update default version to ${{
steps.update-default-version.outputs.latest-version }}"
base: main
labels: "automated-pr,default-version-update"
branch: update-default-version-pr
delete-branch: true

View File

@ -0,0 +1,32 @@
name: "Update known checksums"
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Update known checksums
id: update-known-checksums
run:
node dist/update-known-checksums/index.js
src/download/checksum/known-checksums.ts ${{ secrets.GITHUB_TOKEN }}
- run: npm install && npm run all
- name: Create Pull Request
uses: peter-evans/create-pull-request@4320041ed380b20e97d388d56a7fb4f9b8c20e79 # v7.0.0
with:
commit-message: "chore: update known checksums"
title:
"chore: update known checksums for ${{
steps.update-known-checksums.outputs.latest-version }}"
body:
"chore: update known checksums for ${{
steps.update-known-checksums.outputs.latest-version }}"
base: main
labels: "automated-pr,update-known-checksums"
branch: update-known-checksums-pr
delete-branch: true

34737
dist/update-known-checksums/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,10 +9,10 @@
"format": "prettier --write .",
"format-check": "prettier --check .",
"lint": "eslint src/**/*.ts --fix",
"package": "ncc build -o dist/setup src/setup-uv.ts && ncc build -o dist/save-cache src/save-cache.ts && ncc build -o dist/update-default-version src/update-default-version.ts",
"package": "ncc build -o dist/setup src/setup-uv.ts && ncc build -o dist/save-cache src/save-cache.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
"test": "jest",
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
"update-default-version": "node dist/update-default-version/index.js src/download/checksum/known-checksums.ts action.yml \"$(gh auth token)\"",
"update-known-checksums": "node dist/update-known-checksums/index.js src/download/checksum/known-checksums.ts \"$(gh auth token)\"",
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
},
"repository": {

View File

@ -1,65 +0,0 @@
import * as github from "@actions/github";
import * as core from "@actions/core";
import { OWNER, REPO } from "./utils/utils";
import { createReadStream, promises as fs } from "fs";
import * as readline from "readline";
import * as semver from "semver";
import { updateChecksums } from "./download/checksum/update-known-checksums";
async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0];
const defaultVersionFilePath = process.argv.slice(2)[1];
const github_token = process.argv.slice(2)[2];
const octokit = github.getOctokit(github_token);
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
owner: OWNER,
repo: REPO,
});
const downloadUrls: string[] = response.flatMap((release) =>
release.assets
.filter((asset) => asset.name.endsWith(".sha256"))
.map((asset) => asset.browser_download_url),
);
await updateChecksums(checksumFilePath, downloadUrls);
const latestVersion = response
.map((release) => release.tag_name)
.sort(semver.rcompare)[0];
core.setOutput("latest-version", latestVersion);
await updateDefaultVersion(defaultVersionFilePath, latestVersion);
}
async function updateDefaultVersion(
filePath: string,
latestVersion: string,
): Promise<void> {
const fileStream = createReadStream(filePath);
const rl = readline.createInterface({
input: fileStream,
});
let foundDescription = false;
const lines = [];
for await (let line of rl) {
if (
!foundDescription &&
line.includes("description: 'The version of uv to install'")
) {
foundDescription = true;
} else if (foundDescription && line.includes("default: ")) {
line = line.replace(/'[^']*'/, `'${latestVersion}'`);
foundDescription = false;
}
lines.push(line);
}
await fs.writeFile(filePath, lines.join("\n"));
}
run();

View File

@ -0,0 +1,32 @@
import * as github from "@actions/github";
import * as core from "@actions/core";
import { OWNER, REPO } from "./utils/utils";
import * as semver from "semver";
import { updateChecksums } from "./download/checksum/update-known-checksums";
async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0];
const github_token = process.argv.slice(2)[1];
const octokit = github.getOctokit(github_token);
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
owner: OWNER,
repo: REPO,
});
const downloadUrls: string[] = response.flatMap((release) =>
release.assets
.filter((asset) => asset.name.endsWith(".sha256"))
.map((asset) => asset.browser_download_url),
);
await updateChecksums(checksumFilePath, downloadUrls);
const latestVersion = response
.map((release) => release.tag_name)
.sort(semver.rcompare)[0];
core.setOutput("latest-version", latestVersion);
}
run();