Skip to content

Commit

Permalink
Switch to Changesets-based release process
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Nov 22, 2021
1 parent 21240c3 commit 20c04cf
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 1,113 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/version-or-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Version or Publish

on:
push:
branches:
- main

jobs:
changesets:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master

- name: Setup Node.js 12.x
uses: actions/setup-node@master
with:
node-version: 12.x

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@master
with:
version: yarn version
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
.parcel-cache
.cache
*.log
*.log

dist/
909 changes: 0 additions & 909 deletions dist/index.js

This file was deleted.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
"@changesets/cli": "^2.9.1",
"@changesets/write": "^0.1.3",
"@changesets/cli": "^2.18.0",
"@changesets/write": "^0.1.5",
"fixturez": "^1.1.0",
"parcel": "^1.12.3",
"prettier": "^2.0.5",
Expand All @@ -14,11 +14,13 @@
"scripts": {
"build": "parcel build ./src/index.ts --no-source-maps --target=node --bundle-node-modules",
"test": "jest",
"test:watch": "yarn test --watch"
"test:watch": "yarn test --watch",
"version": "changeset version",
"release": "node ./scripts/release.js"
},
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"@actions/exec": "^1.1.0",
"@actions/github": "^4.0.0",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
Expand All @@ -42,9 +44,7 @@
"unified": "^8.3.2"
},
"husky": {
"hooks": {
"pre-commit": "yarn build && git add dist/index.js"
}
"hooks": {}
},
"prettier": {}
}
35 changes: 35 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require("path");
const { exec, getExecOutput } = require("@actions/exec");
const tag = `v${require("../package.json").version}`;

process.chdir(path.join(__dirname, ".."));

(async () => {
const { exitCode, stderr } = await getExecOutput(
`git`,
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
{
ignoreReturnCode: true,
}
);
const exists = stdout.trim() !== "";
if (exitCode === 0) {
console.log(
`Action is not being published because version ${tag} is already published`
);
return;
}
if (exitCode !== 2) {
throw new Error(`git ls-remote exited with ${exitCode}:\n${stderr}`);
}

await exec("yarn", ["build"]);

await exec("git", ["checkout", "--detach"]);
await exec("git", ["add", "--force", "dist"]);
await exec("git", ["commit", "-m", tag]);

await exec("changeset", ["tag"]);

await exec("git", ["push", "origin", tag]);
})();
19 changes: 19 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require("fs");
const path = require("path");
const { exec } = require("@actions/exec");

process.chdir(path.join(__dirname, ".."));

(async () => {
await exec("changeset", ["version"]);

const tag = `v${require("../package.json").version}`;

const readmePath = path.join(__dirname, "..", "README.md");
const content = fs.readFileSync(readmePath, "utf8");
const updatedContent = content.replace(
/changesets\/action@[^\s]+/g,
`changesets/action@${tag}`
);
fs.writeFileSync(readmePath, updatedContent);
})();
Loading

0 comments on commit 20c04cf

Please sign in to comment.