Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changesetsの導入 #1298

Merged
merged 15 commits into from
Jul 23, 2023
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)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "voyagegroup/ingred-ui"
}
],
"access": "public",
"baseBranch": "master"
}
5 changes: 5 additions & 0 deletions .changeset/dry-hairs-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ingred-ui": patch
---

introduce changeset
76 changes: 76 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,92 @@ on:
pull_request:

jobs:
generate-changeset:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: install
run: make -f ci.mk install
- name: git config
run: |
git config --local user.name ${{ secrets.FLUCT_MEMBER_GITHUB_USER_NAME }}
git config --local user.email ${{ secrets.FLUCT_MEMBER_GITHUB_USER_EMAIL }}
- name: generate changeset
uses: actions/github-script@v6
with:
script: |
const { promises: fs } = require('fs');

// Parses package.json files and returns the package names
async function getPackagesNames(files) {
const names = [];
for (const file of files) {
const data = JSON.parse(await fs.readFile(file, 'utf8'));
if (!data.private) {
names.push(data.name);
}
}
return names;
}

async function createChangeset(fileName, commitMessage, packages) {
const pkgs = packages.map(pkg => `'${pkg}': patch`).join('\n');
const message = commitMessage.replace(/([bB])ump ([\S]+)/, '$1ump `$2`').trim();
const body = `---\n${pkgs}\n---\n\n${message}\n`;
await fs.writeFile(fileName, body);
}

const branch = await exec.getExecOutput('git branch --show-current');
if (!branch.stdout.startsWith('dependabot/')) {
console.log('Not a dependabot branch, skipping');
return;
}

const diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1');
const diffFiles = diffOutput.stdout.split('\n');

if (diffFiles.find(f => f.startsWith('.changeset'))) {
console.log('Changeset already exists, skipping');
return;
}

const files = diffFiles
.filter(file => file !== 'package.json') // skip root package.json
.filter(file => file.includes('package.json'));

const packageNames = await getPackagesNames(files);
if (!packageNames.length) {
console.log('No package.json changes to published packages, skipping');
return;
}

const { stdout: shortHash } = await exec.getExecOutput('git rev-parse --short HEAD');
const fileName = `.changeset/dependabot-${shortHash.trim()}.md`;
const { stdout: commitMessage } = await exec.getExecOutput('git show --pretty=format:%s -s HEAD');
await createChangeset(fileName, commitMessage, packageNames);
await exec.exec('git', ['add', fileName]);
await exec.exec('git commit -C HEAD --amend --no-edit');
await exec.exec('git push --force');
test-lint-and-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: install
run: make -f ci.mk install
- name: check changesets
run: make -f ci.mk check_changesets
- name: lint
run: make -f ci.mk lint
- name: test
Expand Down
35 changes: 8 additions & 27 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,13 @@ jobs:
run: make -f ci.mk lint
- name: test
run: make -f ci.mk test
- name: npm version
run: make -f ci.mk release_version
env:
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
- name: git config
run: |
git config --local user.name ${{ secrets.FLUCT_MEMBER_GITHUB_USER_NAME }}
git config --local user.email ${{ secrets.FLUCT_MEMBER_GITHUB_USER_EMAIL }}
- name: git add & commit & push
run: |
git add package.json
git commit -m "[ci skip] release v${{ env.RELEASE_VERSION }}"
git push
env:
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
- name: npm publish
run: make -f ci.mk publish
env:
NPM_TOKEN: ${{ secrets.FLUCT_NPM_TOKEN }}
- name: Create Tag & Release
uses: ncipollo/release-action@v1
- name: build
run: make -f ci.mk build
- name: Create Release Pull Request or Publish to npm
id: check_changesets
uses: changesets/action@v1
with:
allowUpdates: true
name: Release ${{ env.RELEASE_TAG_NAME }}
tag: ${{ env.RELEASE_TAG_NAME }}
token: ${{ secrets.FLUCT_MEMBER_GITHUB_TOKEN }}
generateReleaseNotes: true
publish: yarn release
env:
RELEASE_TAG_NAME: v${{ github.event.inputs.release_version }}
GITHUB_TOKEN: ${{ secrets.FLUCT_MEMBER_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.FLUCT_NPM_TOKEN }}
3 changes: 3 additions & 0 deletions ci.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ lint:
build:
yarn build

check_changesets:
yarn changeset status --since origin/master

release_version:
npm config set git-tag-version false
npm version ${RELEASE_VERSION}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build-storybook": "storybook build",
"lint": "tsc && eslint 'src/**/*.{ts,tsx}' && prettier --check 'src/**/*.{ts,tsx}'",
"format": "prettier --write 'src/**/*.{ts,tsx}'",
"generate": "yarn scaffdog generate"
"generate": "yarn scaffdog generate",
"release": "changeset tag && changeset publish"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changeset publishだとtagを生成してくれなかった
自分の検証だとこれでうまくいった
https://github.com/penicillin0/npm-changeset-test/actions/runs/5445896381

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
"dependencies": {
"@floating-ui/react": "^0.24.3",
Expand All @@ -42,6 +43,8 @@
"@babel/preset-env": "^7.21.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.4",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@rollup/plugin-commonjs": "25.0.0",
"@rollup/plugin-node-resolve": "15.1.0",
"@rollup/plugin-terser": "0.4.3",
Expand Down
Loading