Skip to content

Commit

Permalink
Switch to Changesets-based release process (#118)
Browse files Browse the repository at this point in the history
* Switch to Changesets-based release process

* Bump version

* drop unused variable

* Update .github/workflows/version-or-publish.yml

Co-authored-by: Nicola Molinari <[email protected]>

* 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 <[email protected]>

* build the action before trying to use it the workflow

* Add changeset and actually setup Changesets, lol

Co-authored-by: Nicola Molinari <[email protected]>
  • Loading branch information
Andarist and emmenko authored Nov 25, 2021
1 parent 21240c3 commit 05c863d
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 1,119 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
13 changes: 13 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "changesets/action" }
],
"commit": false,
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/witty-walls-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": major
---

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.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
- uses: actions/checkout@v2

- name: Use Node.js 12
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x

- name: Install dependencies
run: yarn
- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Test
run: yarn test
33 changes: 33 additions & 0 deletions .github/workflows/version-or-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Version or Publish

on:
push:
branches:
- main

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

- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Build
run: yarn build

- name: Create Release Pull Request or Publish
id: changesets
uses: .
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/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @changesets/action
909 changes: 0 additions & 909 deletions dist/index.js

This file was deleted.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@changesets/action",
"version": "0.1.0",
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
"@changesets/cli": "^2.9.1",
"@changesets/write": "^0.1.3",
"@changesets/changelog-github": "^0.4.1",
"@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 +15,14 @@
"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",
"changeset": "changeset",
"version": "node ./scripts/version.js",
"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 +46,7 @@
"unified": "^8.3.2"
},
"husky": {
"hooks": {
"pre-commit": "yarn build && git add dist/index.js"
}
"hooks": {}
},
"prettier": {}
}
41 changes: 41 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const path = require("path");
const { exec, getExecOutput } = require("@actions/exec");

const { version } = require("../package.json");
const tag = `v${version}`;
const releaseLine = `v${version.split(".")[0]}`;

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

(async () => {
const { exitCode, stderr } = await getExecOutput(
`git`,
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
{
ignoreReturnCode: true,
}
);
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("git", ["checkout", "--detach"]);
await exec("git", ["add", "--force", "dist"]);
await exec("git", ["commit", "-m", tag]);

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

await exec("git", [
"push",
"--force",
"--follow-tags",
"origin",
`HEAD:refs/heads/${releaseLine}`,
]);
})();
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 releaseLine = `v${require("../package.json").version.split(".")[0]}`;

const readmePath = path.join(__dirname, "..", "README.md");
const content = fs.readFileSync(readmePath, "utf8");
const updatedContent = content.replace(
/changesets\/action@[^\s]+/g,
`changesets/action@${releaseLine}`
);
fs.writeFileSync(readmePath, updatedContent);
})();
2 changes: 1 addition & 1 deletion src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Array [
### Patch Changes
- Updated dependencies [undefined]
- Updated dependencies
- simple-project-pkg-b@1.1.0
## simple-project-pkg-b@1.1.0
Expand Down
Loading

0 comments on commit 05c863d

Please sign in to comment.