Skip to content

Commit 6c1b0b6

Browse files
authored
Merge pull request #571 from Shopify/changesets
Testing Changesets
2 parents 03a639d + a66f720 commit 6c1b0b6

File tree

7 files changed

+1062
-20
lines changed

7 files changed

+1062
-20
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": ["@changesets/changelog-github", {"repo": "Shopify/draggable"}],
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/workflows/changelog.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Changelog
2+
3+
on:
4+
pull_request:
5+
types:
6+
- labeled
7+
- unlabeled
8+
- opened
9+
- synchronize
10+
- reopened
11+
12+
jobs:
13+
check:
14+
if: |
15+
!contains(github.event.pull_request.head.ref, 'changeset-release') &&
16+
!contains(github.event.pull_request.labels.*.name, '🤖Skip Changelog')
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout branch
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: 18.17.1
28+
29+
- name: Check for Changeset
30+
run: npx @changesets/cli status --since="origin/main"

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v3
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: '18.17.1'
24+
cache: 'yarn'
25+
26+
- name: Install dependencies
27+
run: yarn --frozen-lockfile
28+
29+
- name: Create release Pull Request or publish to NPM
30+
id: changesets
31+
uses: changesets/action@v1
32+
with:
33+
version: yarn version-packages
34+
publish: yarn release
35+
env:
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/snapit.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Snapshot
2+
3+
on:
4+
issue_comment:
5+
types:
6+
- created
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
snapshot:
12+
name: Snapshot Release
13+
if: |
14+
github.event.issue.pull_request &&
15+
(startsWith(github.event.comment.body, '/snapit') || startsWith(github.event.comment.body, '/snapshot-release'))
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Enforce permission requirement
19+
uses: prince-chrismc/check-actor-permissions-action@v1
20+
with:
21+
permission: write
22+
23+
- name: Add initial reaction
24+
uses: peter-evans/create-or-update-comment@v2
25+
with:
26+
comment-id: ${{ github.event.comment.id }}
27+
reactions: eyes
28+
29+
- name: Validate pull request
30+
uses: actions/github-script@v6
31+
id: pr_data
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
with:
35+
script: |
36+
try {
37+
const pullRequest = await github.rest.pulls.get({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
pull_number: context.issue.number,
41+
})
42+
43+
// Pull request from fork
44+
if (context.payload.repository.full_name !== pullRequest.data.head.repo.full_name) {
45+
const errorMessage = '`/snapit` is not supported on pull requests from forked repositories.'
46+
47+
await github.rest.issues.createComment({
48+
issue_number: context.issue.number,
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
body: errorMessage,
52+
})
53+
54+
core.setFailed(errorMessage)
55+
}
56+
} catch (err) {
57+
core.setFailed(`Request failed with error ${err}`)
58+
}
59+
60+
- name: Checkout default branch
61+
uses: actions/checkout@v3
62+
63+
# issue_comment requires us to checkout the branch
64+
# https://github.com/actions/checkout/issues/331#issuecomment-1120113003
65+
- name: Checkout pull request branch
66+
run: hub pr checkout ${{ github.event.issue.number }}
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
70+
# Because changeset entries are consumed and removed on the
71+
# 'changeset-release/main' branch, we need to reset the files
72+
# so the following 'changeset version --snapshot' command will
73+
# regenerate the package version bumps with the snapshot releases
74+
- name: Reset changeset entries on changeset-release/main branch
75+
run: |
76+
if [[ $(git branch --show-current) == 'changeset-release/main' ]]; then
77+
git checkout origin/main -- .changeset
78+
fi
79+
80+
- name: Setup Node.js
81+
uses: actions/setup-node@v3
82+
with:
83+
node-version: '18.17.1'
84+
85+
- name: Install dependencies
86+
run: yarn --frozen-lockfile
87+
88+
- name: Create an .npmrc
89+
env:
90+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
91+
run: |
92+
cat << EOF > "$HOME/.npmrc"
93+
//registry.npmjs.org/:_authToken=$NPM_TOKEN
94+
EOF
95+
96+
- name: Create and publish snapshot release
97+
uses: actions/github-script@v6
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
with:
101+
script: |
102+
const execa = require('execa')
103+
104+
const releaseProcess = execa.command('yarn release -- --no-git-tags --snapshot --tag snapshot-release')
105+
releaseProcess.stdout.pipe(process.stdout)
106+
107+
const {stdout} = await releaseProcess
108+
109+
const newTags = Array
110+
.from(stdout.matchAll(/New tag:\s+([^\s\n]+)/g))
111+
.map(([_, tag]) => tag)
112+
113+
if (newTags.length) {
114+
const multiple = newTags.length > 1
115+
116+
const body = (
117+
`🫰✨ **Thanks @${context.actor}! ` +
118+
`Your snapshot${multiple ? 's have' : ' has'} been published to npm.**\n\n` +
119+
`Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` ` +
120+
`with the newly published version${multiple ? 's' : ''}:\n` +
121+
newTags.map(tag => (
122+
'```sh\n' +
123+
`yarn add ${tag}\n` +
124+
'```'
125+
)).join('\n')
126+
)
127+
await github.rest.issues.createComment({
128+
issue_number: context.issue.number,
129+
owner: context.repo.owner,
130+
repo: context.repo.repo,
131+
body,
132+
})
133+
}
134+
135+
- name: Add final reaction
136+
uses: peter-evans/create-or-update-comment@v2
137+
with:
138+
comment-id: ${{ github.event.comment.id }}
139+
reactions: rocket

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
"start": "concurrently \"yarn watch\" \"cd examples && yarn && yarn start\"",
2929
"build": "yarn build:production",
3030
"watch": "ts-node --project='./scripts/tsconfig.json' ./scripts/watch.ts",
31-
"prepare": "yarn build:development",
32-
"prepublishOnly": "yarn build:production",
31+
"release": "yarn run build:production && changeset publish",
3332
"lint": "eslint ./src ./scripts ./test --max-warnings 0",
3433
"type-check": "tsc --noEmit",
3534
"type-check:scripts": "tsc --noEmit --project scripts",
@@ -46,6 +45,8 @@
4645
],
4746
"devDependencies": {
4847
"@babel/core": "^7.22.20",
48+
"@changesets/changelog-github": "^0.4.8",
49+
"@changesets/cli": "^2.26.2",
4950
"@microsoft/tsdoc": "^0.14.2",
5051
"@shopify/babel-preset": "^25.0.0",
5152
"@shopify/eslint-plugin": "^43.0.0",

0 commit comments

Comments
 (0)