Skip to content

Commit 05c863d

Browse files
Andaristemmenko
andauthored
Switch to Changesets-based release process (changesets#118)
* Switch to Changesets-based release process * Bump version * drop unused variable * Update .github/workflows/version-or-publish.yml Co-authored-by: Nicola Molinari <nicola.molinari@commercetools.com> * Push also to a release line branch when releasing * Change node version used in the version-or-publish workflow * Switch to using the local action Co-authored-by: Nicola Molinari <nicola.molinari@commercetools.com> * build the action before trying to use it the workflow * Add changeset and actually setup Changesets, lol Co-authored-by: Nicola Molinari <nicola.molinari@commercetools.com>
1 parent 21240c3 commit 05c863d

13 files changed

+448
-1119
lines changed

.changeset/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@1.6.2/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "changesets/action" }
6+
],
7+
"commit": false,
8+
"linked": [],
9+
"access": "restricted",
10+
"baseBranch": "main",
11+
"updateInternalDependencies": "patch",
12+
"ignore": []
13+
}

.changeset/witty-walls-allow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/action": major
3+
---
4+
5+
From now on this action will be released using the Changesets-based workflow (using itself). Thanks to that we'll have a good release history. The users will be able to find specific versions of the action and will be able to track changes over time. It also improves the security as the build artifact will always get built in the CI environment, using a frozen lockfile.

.github/workflows/ci.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12+
- name: Checkout Repo
1213
- uses: actions/checkout@v2
1314

14-
- name: Use Node.js 12
15+
- name: Use Node.js 14
1516
uses: actions/setup-node@v1
1617
with:
17-
node-version: 12.x
18+
node-version: 14.x
1819

19-
- name: Install dependencies
20-
run: yarn
20+
- name: Install Dependencies
21+
run: yarn --frozen-lockfile
2122

2223
- name: Test
2324
run: yarn test
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Version or Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
changesets:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo
13+
uses: actions/checkout@v2
14+
15+
- name: Use Node.js 14
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: 14.x
19+
20+
- name: Install Dependencies
21+
run: yarn --frozen-lockfile
22+
23+
- name: Build
24+
run: yarn build
25+
26+
- name: Create Release Pull Request or Publish
27+
id: changesets
28+
uses: .
29+
with:
30+
version: yarn version
31+
publish: yarn release
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
22
.parcel-cache
33
.cache
4-
*.log
4+
*.log
5+
6+
dist/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @changesets/action

dist/index.js

-909
This file was deleted.

package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "@changesets/action",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"main": "dist/index.js",
55
"license": "MIT",
66
"devDependencies": {
7-
"@changesets/cli": "^2.9.1",
8-
"@changesets/write": "^0.1.3",
7+
"@changesets/changelog-github": "^0.4.1",
8+
"@changesets/cli": "^2.18.0",
9+
"@changesets/write": "^0.1.5",
910
"fixturez": "^1.1.0",
1011
"parcel": "^1.12.3",
1112
"prettier": "^2.0.5",
@@ -14,11 +15,14 @@
1415
"scripts": {
1516
"build": "parcel build ./src/index.ts --no-source-maps --target=node --bundle-node-modules",
1617
"test": "jest",
17-
"test:watch": "yarn test --watch"
18+
"test:watch": "yarn test --watch",
19+
"changeset": "changeset",
20+
"version": "node ./scripts/version.js",
21+
"release": "node ./scripts/release.js"
1822
},
1923
"dependencies": {
2024
"@actions/core": "^1.2.4",
21-
"@actions/exec": "^1.0.4",
25+
"@actions/exec": "^1.1.0",
2226
"@actions/github": "^4.0.0",
2327
"@babel/core": "^7.13.10",
2428
"@babel/preset-env": "^7.13.10",
@@ -42,9 +46,7 @@
4246
"unified": "^8.3.2"
4347
},
4448
"husky": {
45-
"hooks": {
46-
"pre-commit": "yarn build && git add dist/index.js"
47-
}
49+
"hooks": {}
4850
},
4951
"prettier": {}
5052
}

scripts/release.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const path = require("path");
2+
const { exec, getExecOutput } = require("@actions/exec");
3+
4+
const { version } = require("../package.json");
5+
const tag = `v${version}`;
6+
const releaseLine = `v${version.split(".")[0]}`;
7+
8+
process.chdir(path.join(__dirname, ".."));
9+
10+
(async () => {
11+
const { exitCode, stderr } = await getExecOutput(
12+
`git`,
13+
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
14+
{
15+
ignoreReturnCode: true,
16+
}
17+
);
18+
if (exitCode === 0) {
19+
console.log(
20+
`Action is not being published because version ${tag} is already published`
21+
);
22+
return;
23+
}
24+
if (exitCode !== 2) {
25+
throw new Error(`git ls-remote exited with ${exitCode}:\n${stderr}`);
26+
}
27+
28+
await exec("git", ["checkout", "--detach"]);
29+
await exec("git", ["add", "--force", "dist"]);
30+
await exec("git", ["commit", "-m", tag]);
31+
32+
await exec("changeset", ["tag"]);
33+
34+
await exec("git", [
35+
"push",
36+
"--force",
37+
"--follow-tags",
38+
"origin",
39+
`HEAD:refs/heads/${releaseLine}`,
40+
]);
41+
})();

scripts/version.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const { exec } = require("@actions/exec");
4+
5+
process.chdir(path.join(__dirname, ".."));
6+
7+
(async () => {
8+
await exec("changeset", ["version"]);
9+
10+
const releaseLine = `v${require("../package.json").version.split(".")[0]}`;
11+
12+
const readmePath = path.join(__dirname, "..", "README.md");
13+
const content = fs.readFileSync(readmePath, "utf8");
14+
const updatedContent = content.replace(
15+
/changesets\/action@[^\s]+/g,
16+
`changesets/action@${releaseLine}`
17+
);
18+
fs.writeFileSync(readmePath, updatedContent);
19+
})();

src/__snapshots__/run.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Array [
1515
1616
### Patch Changes
1717
18-
- Updated dependencies [undefined]
18+
- Updated dependencies
1919
- simple-project-pkg-b@1.1.0
2020
2121
## simple-project-pkg-b@1.1.0

0 commit comments

Comments
 (0)