Skip to content

Commit 59a0afe

Browse files
dependabot[bot]swiftylab-cisoumyamahunt
authored
refactor: update swift-org-website released tools parsing (#54)
* build(swift-org-website): bump swiftorg from `1f57d0e` to `e851408` Bumps [swiftorg](https://github.com/apple/swift-org-website) from `1f57d0e` to `e851408`. - [Commits](swiftlang/swift-org-website@1f57d0e...e851408) --- updated-dependencies: - dependency-name: swiftorg dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * [skip dependabot] wip: update package.json * [skip dependabot] refactor: update swift-org-website released tools parsing --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: swiftylab-ci <swiftylab.bot@gmail.com> Co-authored-by: Soumya Ranjan Mahunt <soumya.mahunt@gmail.com>
1 parent 22bf437 commit 59a0afe

File tree

22 files changed

+27957
-172777
lines changed

22 files changed

+27957
-172777
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"eamodio.gitlens",
1313
"ms-vscode.vscode-typescript-next",
1414
"Orta.vscode-jest",
15-
"dbaeumer.vscode-eslint"
15+
"dbaeumer.vscode-eslint",
16+
"github.vscode-github-actions"
1617
]
1718
}
1819
},

.github/changelog/pre_commit_hook.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
11
'use strict'
2+
const path = require('path');
3+
const fs = require('fs').promises;
24
const core = require('@actions/core');
35
const {exec, getExecOutput} = require('@actions/exec');
6+
const yaml = require('js-yaml');
7+
const semver = require('semver');
8+
const PackageJson = require('@npmcli/package-json');
49

5-
exports.preCommit = async (props) => {
10+
const SWIFT_ORG_BUILD = path.join('swiftorg', '_data', 'builds');
11+
12+
async function swiftorgCommit() {
613
const gitOptions = {cwd: 'swiftorg'};
714
const {stdout} = await getExecOutput('git', ['rev-parse', '--verify', 'HEAD'], gitOptions);
8-
const swiftorg = stdout.trim();
9-
core.info(`Updating swiftorg to "${swiftorg}"`);
10-
await exec('npm', ['pkg', 'set', `swiftorg=${swiftorg}`]);
15+
return stdout.trim();
16+
}
17+
18+
async function latestRelease() {
19+
const swiftRelease = path.join(SWIFT_ORG_BUILD, 'swift_releases.yml');
20+
const releaseData = await fs.readFile(swiftRelease, 'utf-8');
21+
const releases = yaml.load(releaseData);
22+
return releases[releases.length - 1];
23+
}
24+
25+
async function latestDevRelease() {
26+
const buildEntries = await fs.readdir(SWIFT_ORG_BUILD, { withFileTypes: true });
27+
const devBranchRegex = /swift-(.*)-branch/;
28+
const devDirs = buildEntries.flatMap(entry => {
29+
if (!entry.isDirectory() || !devBranchRegex.exec(entry.name)) {
30+
return [];
31+
}
32+
return entry.name;
33+
}).sort((dir1, dir2) => {
34+
const ver1 = devBranchRegex.exec(dir1)[1].replace('_', '.');
35+
const ver2 = devBranchRegex.exec(dir2)[1].replace('_', '.');
36+
return semver.gt(semver.coerce(ver2), semver.coerce(ver1)) ? 1 : -1;
37+
});
38+
const devVer = devBranchRegex.exec(devDirs[0])[1].replace('_', '.');
39+
const xcodeSnapshot = path.join(SWIFT_ORG_BUILD,devDirs[0], 'xcode.yml');
40+
const devReleaseData = await fs.readFile(xcodeSnapshot, 'utf-8');
41+
const devReleases = yaml.load(devReleaseData);
42+
return { name: devVer, date: devReleases[0].date, tag: devReleases[0].dir };
43+
}
44+
45+
async function latestSnapshot() {
46+
const xcodeSnapshot = path.join(SWIFT_ORG_BUILD, 'development', 'xcode.yml');
47+
const devSnapshotsData = await fs.readFile(xcodeSnapshot, 'utf-8');
48+
const snapshots = yaml.load(devSnapshotsData);
49+
return { date: snapshots[0].date, tag: snapshots[0].dir };
50+
}
51+
52+
exports.preCommit = async (props) => {
53+
const commit = await swiftorgCommit();
54+
const release = await latestRelease();
55+
const dev = await latestDevRelease();
56+
const snapshot = await latestSnapshot();
57+
58+
const swiftorg = { commit: commit, release: release, dev: dev, snapshot: snapshot };
59+
const pkgJson = await PackageJson.load('./');
60+
core.info(`Updating swiftorg metadata to "${JSON.stringify(swiftorg)}"`);
61+
pkgJson.update({ swiftorg: swiftorg });
62+
await pkgJson.save();
1163

1264
core.startGroup(`Bundling`);
1365
await exec('npm install');

.github/workflows/approve.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Approve pull request if not already approved
18-
run: |
19-
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
20-
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
21-
then gh pr review --approve "$PR_URL"
22-
else echo "PR already approved, skipping additional approvals to minimize emails/notification noise.";
23-
fi
18+
run: gh pr review --approve "${{ github.event.issue.pull_request.html_url }}"
2419
env:
25-
PR_URL: ${{ github.event.issue.pull_request.html_url }}
2620
GITHUB_TOKEN: ${{ secrets.COMMIT_TOKEN }}

0 commit comments

Comments
 (0)