add: changesets + snapshot-this action (#1746)

* add: changesets + snapshot-this action

* add: changeset folder

* add: action credits
This commit is contained in:
Zakaria El Asri
2022-06-30 10:07:18 +01:00
committed by GitHub
parent 9e0f65dee3
commit 55978e9e81
5 changed files with 817 additions and 28 deletions

8
.changeset/README.md Normal file
View File

@@ -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
.changeset/config.json Normal file
View File

@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "medusajs/medusa" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}

133
.github/workflows/snapshot-this.yml vendored Normal file
View File

@@ -0,0 +1,133 @@
# Inspired from https://github.com/Shopify/quilt/blob/main/.github/workflows/snapit.yml
name: Snapshot This
on:
issue_comment:
types:
- created
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
snapshot:
name: Snapshot Release
if: |
github.event.issue.pull_request &&
github.event.comment.body == '/snapshot-this'
runs-on: ubuntu-latest
steps:
- name: Validate pull request
uses: actions/github-script@v6
with:
script: |
try {
// Add a rocket reaction to the comment
await github.rest.reactions.createForIssueComment({
...context.repo,
comment_id: context.payload.comment.id,
content: 'rocket',
})
// Only allow comment creators who have "write" permissions to repo
const actorPermission = (await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo,
username: context.actor
})).data.permission
const isPermitted = ['write', 'admin'].includes(actorPermission)
if (!isPermitted) {
const errorMessage = 'Only users with write permission to the respository can run /snapshot-this'
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: errorMessage,
})
core.setFailed(errorMessage)
return;
}
const pullRequest = await github.rest.pulls.get({
...context.repo,
pull_number: context.issue.number,
})
// Pull request from fork
if (context.payload.repository.full_name !== pullRequest.data.head.repo.full_name) {
const errorMessage = '`/snapshot-this` is not supported on pull requests from forked repositories.'
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: errorMessage,
})
core.setFailed(errorMessage)
}
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: Checkout pull request branch
uses: actions/checkout@v2
with:
ref: ${{ format('refs/pull/{0}/merge', github.event.issue.number) }}
# Because changeset entries are consumed and removed on the
# 'changeset-release/main' branch, we need to reset the files
# so the following 'changeset version --snapshot' command will
# regenerate the package version bumps with the snapshot releases
- name: Reset changeset entries on changeset-release/main branch
run: |
if [[ $(git branch --show-current) == 'changeset-release/main' ]]; then
git checkout origin/main -- .changeset
fi
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: "yarn"
- name: Bootstrap packages
uses: ./.github/actions/cache-bootstrap
with:
extension: snapshot-this
- name: Create an .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
- name: Create and publish snapshot release
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
await exec.exec('yarn run changeset version --snapshot snapshot')
const {stdout} = await exec.getExecOutput('yarn run release:snapshot')
const newTags = Array
.from(stdout.matchAll(/New tag:\s+([^\s\n]+)/g))
.map(([_, tag]) => tag)
if (newTags.length) {
const multiple = newTags.length > 1
const body = (
`#### :rocket: A snapshot release has been made for this PR\n\n` +
`Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` ` +
`with the newly published version${multiple ? 's' : ''}:\n` +
newTags.map(tag => (
'```sh\n' +
`yarn add ${tag}\n` +
'```'
)).join('\n') +
`\n\n> Latest commit: ${context.sha}`
)
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body,
})
await github.rest.reactions.createForIssueComment({
...context.repo,
comment_id: context.payload.comment.id,
content: 'hooray',
})
}

View File

@@ -67,9 +67,12 @@
"test:integration:api": "jest --config=integration-tests/jest.config.js --projects=integration-tests/api", "test:integration:api": "jest --config=integration-tests/jest.config.js --projects=integration-tests/api",
"test:integration:plugins": "jest --config=integration-tests/jest.config.js --projects=integration-tests/plugins", "test:integration:plugins": "jest --config=integration-tests/jest.config.js --projects=integration-tests/plugins",
"test:fixtures": "jest --config=docs-util/jest.config.js --runInBand", "test:fixtures": "jest --config=docs-util/jest.config.js --runInBand",
"generate:services": "typedoc --options typedoc.services.js" "generate:services": "typedoc --options typedoc.services.js",
"release:snapshot": "changeset publish --no-git-tags --snapshot --tag snapshot"
}, },
"dependencies": { "dependencies": {
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.0",
"global": "^4.4.0", "global": "^4.4.0",
"import-from": "^3.0.0", "import-from": "^3.0.0",
"oas-normalize": "^5.0.1", "oas-normalize": "^5.0.1",

688
yarn.lock

File diff suppressed because it is too large Load Diff