Skip to content
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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"eamodio.gitlens",
"ms-vscode.vscode-typescript-next",
"Orta.vscode-jest",
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"github.vscode-github-actions"
]
}
},
Expand Down
60 changes: 56 additions & 4 deletions .github/changelog/pre_commit_hook.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,65 @@
'use strict'
const path = require('path');
const fs = require('fs').promises;
const core = require('@actions/core');
const {exec, getExecOutput} = require('@actions/exec');
const yaml = require('js-yaml');
const semver = require('semver');
const PackageJson = require('@npmcli/package-json');

exports.preCommit = async (props) => {
const SWIFT_ORG_BUILD = path.join('swiftorg', '_data', 'builds');

async function swiftorgCommit() {
const gitOptions = {cwd: 'swiftorg'};
const {stdout} = await getExecOutput('git', ['rev-parse', '--verify', 'HEAD'], gitOptions);
const swiftorg = stdout.trim();
core.info(`Updating swiftorg to "${swiftorg}"`);
await exec('npm', ['pkg', 'set', `swiftorg=${swiftorg}`]);
return stdout.trim();
}

async function latestRelease() {
const swiftRelease = path.join(SWIFT_ORG_BUILD, 'swift_releases.yml');
const releaseData = await fs.readFile(swiftRelease, 'utf-8');
const releases = yaml.load(releaseData);
return releases[releases.length - 1];
}

async function latestDevRelease() {
const buildEntries = await fs.readdir(SWIFT_ORG_BUILD, { withFileTypes: true });
const devBranchRegex = /swift-(.*)-branch/;
const devDirs = buildEntries.flatMap(entry => {
if (!entry.isDirectory() || !devBranchRegex.exec(entry.name)) {
return [];
}
return entry.name;
}).sort((dir1, dir2) => {
const ver1 = devBranchRegex.exec(dir1)[1].replace('_', '.');
const ver2 = devBranchRegex.exec(dir2)[1].replace('_', '.');
return semver.gt(semver.coerce(ver2), semver.coerce(ver1)) ? 1 : -1;
});
const devVer = devBranchRegex.exec(devDirs[0])[1].replace('_', '.');
const xcodeSnapshot = path.join(SWIFT_ORG_BUILD,devDirs[0], 'xcode.yml');
const devReleaseData = await fs.readFile(xcodeSnapshot, 'utf-8');
const devReleases = yaml.load(devReleaseData);
return { name: devVer, date: devReleases[0].date, tag: devReleases[0].dir };
}

async function latestSnapshot() {
const xcodeSnapshot = path.join(SWIFT_ORG_BUILD, 'development', 'xcode.yml');
const devSnapshotsData = await fs.readFile(xcodeSnapshot, 'utf-8');
const snapshots = yaml.load(devSnapshotsData);
return { date: snapshots[0].date, tag: snapshots[0].dir };
}

exports.preCommit = async (props) => {
const commit = await swiftorgCommit();
const release = await latestRelease();
const dev = await latestDevRelease();
const snapshot = await latestSnapshot();

const swiftorg = { commit: commit, release: release, dev: dev, snapshot: snapshot };
const pkgJson = await PackageJson.load('./');
core.info(`Updating swiftorg metadata to "${JSON.stringify(swiftorg)}"`);
pkgJson.update({ swiftorg: swiftorg });
await pkgJson.save();

core.startGroup(`Bundling`);
await exec('npm install');
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Approve pull request if not already approved
run: |
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
then gh pr review --approve "$PR_URL"
else echo "PR already approved, skipping additional approvals to minimize emails/notification noise.";
fi
run: gh pr review --approve "${{ github.event.issue.pull_request.html_url }}"
env:
PR_URL: ${{ github.event.issue.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.COMMIT_TOKEN }}
Loading