Skip to content

Commit

Permalink
fix: use shell for last commit and add comapre script
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-go committed Feb 10, 2022
1 parent b7a6a0b commit f925d6f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 38 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/update-compat-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: tc39/test262
path: build/test262
repository: kangax/compat-table
path: packages/babel-compat-data/build/compat-table
- name: Use Node.js latest
uses: actions/setup-node@v2-beta
with:
node-version: "*"
- name: Get latest kangax/compat-data commit
id: lastCommit
run: echo "::set-output name=sha1::$(node ./scripts/update-compat-data/get-last-commit.js)"
run: echo "::set-output name=sha1::$(node ./scripts/update-compat-data/get-last-commit.sh)"
- name: Compare last kangax/compat-data commit with current one
run: echo ${{ steps.lastCommit.outputs.sha1 }} | node ./scripts/update-compat-data/compare-with-current-commit.js
- name: Update compat-data commit
run: echo ${{ steps.lastCommit.outputs.sha1 }} | ./scripts/update-compat-data/bump-data-compat-version.sh
- name: Run update script
Expand Down
49 changes: 49 additions & 0 deletions scripts/update-compat-data/compare-with-current-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { readFile } from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const CURRENT_COMMIT_VARIABLE_NAME = "COMPAT_TABLE_COMMIT";

async function getCurrentCommit() {
const target = path.join(
__dirname,
"..",
"..",
"packages",
"babel-compat-data",
"scripts",
"download-compat-table.sh"
);
const lines = (await readFile(target, { encoding: "utf-8" })).split("\n");

for (const line of lines) {
if (line.includes(CURRENT_COMMIT_VARIABLE_NAME)) {
return line.split("=").at(1);
}
}

return undefined;
}

async function checkCurrentCommit(lastCommit) {
if (typeof lastCommit !== "string") {
throw new Error(`Last commit should be provided but got ${lastCommit}`);
}

const currentCommit = await getCurrentCommit();
if (typeof lastCommit !== "string") {
throw new Error("Not valid current commit found: ${currentCommit}");
}

console.log("last commit :", lastCommit);
console.log("current commit :", currentCommit);

if (lastCommit === currentCommit) {
throw new Error("compat-data doesn't need to be updated");
}

return lastCommit;
}

checkCurrentCommit(process.argv[2]).then(console.log);
35 changes: 0 additions & 35 deletions scripts/update-compat-data/get-last-commit.js

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/update-compat-data/get-last-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e
export GIT_DIR=./packages/babel-compat-data/build/compat-table
git fetch -q origin HEAD
git rev-parse FETCH_HEAD

0 comments on commit f925d6f

Please sign in to comment.