Skip to content

Commit

Permalink
init nvchecker
Browse files Browse the repository at this point in the history
  • Loading branch information
YangMame committed May 22, 2024
1 parent 5de2589 commit 94fd76b
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 0 deletions.
144 changes: 144 additions & 0 deletions .github/workflows/issues-bumper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
async function getSearchIssuesResult(github, repo_name, titleSearchKeyword, page_number) {
// repo_name = "microcai/gentoo-zh";
searchQuery = `repo:${repo_name} is:issue label:nvchecker in:title ${titleSearchKeyword}`;
const searchIssues = await github.rest.search.issuesAndPullRequests({
q: searchQuery,
per_page: 100,
page: page_number,
});
return searchIssues.data.items;
}

function getGithubAccount(package) {
var toml = require("toml");
var fs = require("fs");
var tomlFileContent = fs.readFileSync(
".github/workflows/overlay.toml",
"utf8"
);

github_account = toml.parse(tomlFileContent)[package]["github_account"];

return github_account;
}

module.exports = async ({ github, context, core }) => {
// hardcode gentoo-zh official repo name
var gig_official_repo_name = "Gig-OS/gig";
var repo_name = process.env.GITHUB_REPOSITORY;
var repo_is_gig_official = repo_name == gig_official_repo_name;

let pkgs = JSON.parse(process.env.pkgs);
for (let pkg of pkgs) {
// // limit "x11-misc/9menu" and "dev-libs/libthai"
// if (pkg.name != "x11-misc/9menu" && pkg.name != "dev-libs/libthai") {
// continue;
// }

titlePrefix = "[nvchecker] " + pkg.name + " can be bump to ";
title = titlePrefix + pkg.newver;
var body = "";
if (pkg.oldver != null) {
body += "oldver: " + pkg.oldver;
}

// append @github_account to body
// only mention user on official gentoo-zh repo
github_accounts = getGithubAccount(pkg.name);
if (typeof github_accounts == "object") {
// multiple accounts example:
// github_account = ["st0nie", "peeweep"]
body += "\nCC:";
for (let github_account of github_accounts) {
body += repo_is_gig_official
? " @" + github_account
: " " + github_account
}
} else if (typeof github_accounts == "string") {
// single account example:
// github_account = "peeweep"
body += repo_is_gig_official
? "\nCC: @" + github_accounts
: "\nCC: " + github_accounts
}

// if body still empty, convert to null
// because github rest api response's issue body is null, they should be same
if (body == "") {
body = null;
}

// search issues by titlePrefix
let issuesData = [];
let page_number = 0;
while (true) {
page_number++;
try {
const response = await getSearchIssuesResult(
github,
repo_name,
titleSearchKeyword = titlePrefix,
page_number
);
issuesData = issuesData.concat(response);
if (response.length < 100) {
break;
}
} catch (error) {
core.warning(`Waring ${error}, action may still succeed though`);
}
}

(async function () {
// search existed in issues
for (let issueData of issuesData) {
// if titlePrefix matched
if (
issueData.title.length >= titlePrefix.length
? issueData.title.substring(0, titlePrefix.length) == titlePrefix
: false
) {
// titlePrefix matched;
if (issueData.body == body && issueData.title == title) {
// if body and title all matched, goto next loop
return;
} else {
// if body or title not matched
if (issueData.state == "open") {
// if state is open, edit it, then goto next loop
// if (!repo_is_gig_official) {
// // only update on official gentoo-zh repo
// return;
// }
const issueUpdate = await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueData.number,
title: title,
body: body,
});
console.log("Edit issue on %s", issueUpdate.data.html_url);
return;
} else {
// if state is clsoe,create new
break;
}
}
}
}
try {
// create new issue
const issuesCreate = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ["nvchecker"],
});
console.log("Created issue on %s", issuesCreate.data.html_url);
} catch (error) {
core.warning(`Waring ${error}, action may still succeed though`);
}
})();
}
};
84 changes: 84 additions & 0 deletions .github/workflows/nvchecker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: nvchecker

on:
push:
workflow_dispatch:
schedule:
# * is a special character in YAML so you have to quote this string
# UTC 09:00 -> CST (China) 17:00, see https://datetime360.com/cn/utc-cst-china-time/
- cron: '0 09 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
nvchecker:
runs-on: ubuntu-latest
container:
image: ghcr.io/gig-os/gentoo-testing:master

steps:
- name: checkout
uses: actions/checkout@v2

- name: gentoo
run: |
# eselect
echo "::group::eselect repository add and sync"
repo_name=$(cat profiles/repo_name)
eselect repository add "$repo_name" git "file://${PWD}"
emerge --sync "$repo_name"
egencache --jobs=$(nproc) --update --repo "$repo_name" &> /dev/null
eix-update
echo "::endgroup::"
# eix
echo "::group::eix search packages"
pkgs=$(ACCEPT_LICENSE="*" ACCEPT_KEYWORDS="~amd64" EIX_LIMIT=0 NAMEVERSION="<category>/<name>-<version>\n" eix --pure-packages --in-overlay "$repo_name" --format '<bestversion:NAMEVERSION>')
pkgs=$(qatom -F "\"%{CATEGORY}/%{PN}\": \"%{PV}\"," $pkgs) # remove revision
echo "$pkgs"
pkgs="{ ${pkgs::-1} }"
echo "$pkgs" > .github/workflows/old_ver.json
cat .github/workflows/old_ver.json
echo "::endgroup::"
- name: nvchecker
id: nvchecker
run: |
echo "::group::nvchecker and nvcmp"
cd .github/workflows/
echo -e "[keys]\ngithub = \"${{ secrets.GITHUB_TOKEN }}\"" > keyfile.toml
nvchecker --file overlay.toml --keyfile keyfile.toml
sed -r -i \
-e 's#(\.|-|_)?a([[:digit:]]+)(",?)$#_alpah\2\3#' \
-e 's#(\.|-|_)?p([[:digit:]]+)(",?)$#_p\2\3#' \
-e 's#(\.|-|_)?rc([[:digit:]]+)(",?)$#_rc\2\3#' \
new_ver.json
cat new_ver.json
echo "nvcmp=$(nvcmp --file overlay.toml --json --newer)" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: setup node
uses: actions/setup-node@v2
with:
node-version: 16

- name: install github-script depends
run: |
npm install toml
- name: update issues
uses: actions/github-script@v6
timeout-minutes: 1
env:
pkgs: ${{steps.nvchecker.outputs.nvcmp}}
with:
github-token: ${{ secrets.NVCHECKER_PAT }} # https://github.com/microcai/gentoo-zh/pull/3130
script: |
const script = require('./.github/workflows/issues-bumper.js');
(async function () {
await script({github, context, core});
})();
84 changes: 84 additions & 0 deletions .github/workflows/overlay.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[__config__]
oldver = "old_ver.json"
newver = "new_ver.json"

["app-admin/cockpit-benchmark"]
source = "github"
github = "45Drives/cockpit-benchmark"
use_latest_tag = true
prefix = "v"

["app-admin/cockpit-file-sharing"]
source = "github"
github = "45Drives/cockpit-file-sharing"
use_latest_tag = true
prefix = "v"

["app-admin/cockpit-machines"]
source = "github"
github = "cockpit-project/cockpit-machines"
use_latest_tag = true
prefix = "v"

["app-admin/cockpit-navigator"]
source = "github"
github = "45Drives/cockpit-navigator"
use_latest_tag = true
prefix = "v"

["app-admin/cockpit-zfs-manager"]
source = "github"
github = "optimans/cockpit-zfs-manager"
use_latest_tag = true
prefix = "v"

["app-admin/cockpit"]
source = "github"
github = "cockpit-project/cockpit"
use_latest_tag = true
prefix = "v"

["app-emulation/libvirt-dbus"]
source = "github"
github = "libvirt/libvirt-dbus"
use_latest_tag = true
prefix = "v"

["app-metrics/pcp"]
source = "github"
github = "performancecopilot/pcp"
use_latest_tag = true
prefix = "v"

["app-misc/tusk"]
source = "github"
github = "klauscfhq/tusk"
use_latest_tag = true
prefix = "v"

["app-shells/shell-gpt"]
source = "github"
github = "TheR1D/shell_gpt"
use_latest_tag = true
prefix = "v"

["dev-python/typer"]
source = "github"
github = "tiangolo/typer"
use_latest_tag = true
prefix = ""

["dev-util/osc"]
source = "github"
github = "openSUSE/osc"
use_latest_tag = true
prefix = ""


["kde-misc/kde-rounded-corners"]
source = "github"
github = "matinlotfali/KDE-Rounded-Corners"
use_latest_tag = true
prefix = "v"


0 comments on commit 94fd76b

Please sign in to comment.