Skip to content

Commit

Permalink
Merge pull request #66 from QwikDev/feat/changesets
Browse files Browse the repository at this point in the history
feat: changesets
  • Loading branch information
thejackshelton authored Mar 9, 2024
2 parents 66d5be8 + 409fec9 commit 4c0c156
Show file tree
Hide file tree
Showing 5 changed files with 1,631 additions and 8 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)
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/config@3.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
160 changes: 160 additions & 0 deletions .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: Create a Snapshot Release

on:
workflow_dispatch:
issue_comment:
types: [created]

defaults:
run:
shell: bash

env:
FORCE_COLOR: 1

jobs:
snapshot-release:
name: Create a snapshot release of a pull request
if: ${{ github.repository_owner == 'QwikDev' && github.event.issue.pull_request && (contains(github.event.comment.body, '!preview') || contains(github.event.comment.body, '/preview') || contains(github.event.comment.body, '!snapshot') || contains(github.event.comment.body, '/snapshot')) }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
issues: write
pull-requests: write
steps:
- name: "Check if user has admin access (only admins can publish snapshot releases)."
uses: "lannonbr/repo-permission-check-action@2.0.0"
with:
permission: "admin"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Extract the snapshot name from comment body
id: getSnapshotName
uses: actions/github-script@v7
with:
script: |
const { body } = context.payload.comment;
const PREVIEW_RE = /^[!\/](?:preview|snapshot)\s+(\S*)\s*$/gim;
const [_, name] = PREVIEW_RE.exec(body) ?? [];
if (name) return name;
const error = 'Invalid command. Expected: "/preview <snapshot-name>"'
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: error,
})
core.setFailed(error)
result-encoding: string

- name: resolve pr refs
id: refs
uses: eficode/resolve-pr-refs@main
with:
token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4
with:
ref: ${{ steps.refs.outputs.head_ref }}
fetch-depth: 0

- run: git checkout main
- run: git checkout ${{ steps.refs.outputs.head_ref }}

- name: Setup PNPM
uses: pnpm/action-setup@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Build Packages
run: pnpm run build

- name: Bump Package Versions
id: changesets
run: |
pnpm exec changeset status --output status.output.json 2>&1
pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }}
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "status<<$EOF" >> $GITHUB_OUTPUT
echo "$(cat status.output.json)" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
env:
# Needs access to run the script
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Disable color
FORCE_COLOR: 0
NO_COLOR: 1

- name: Publish Release
id: publish
run: |
GITHUB_ACTIONS=0 pnpm run build > build.output.txt 2>&1
pnpm exec changeset publish --tag experimental--${{ steps.getSnapshotName.outputs.result }} > publish.output.txt 2>&1
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "build<<$EOF" >> $GITHUB_OUTPUT
echo "$(cat build.output.txt)" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
cat build.output.txt
echo "publish<<$EOF" >> $GITHUB_OUTPUT
echo "$(cat publish.output.txt)" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
cat publish.output.txt
env:
# Needs access to publish to npm
NPM_TOKEN: ${{ secrets.CHANGESETS_RELEASE_PR_WORKFLOW_NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.CHANGESETS_RELEASE_PR_WORKFLOW_NPM_TOKEN }}
# Disable color
FORCE_COLOR: 0
NO_COLOR: 1

- name: Pull Request Notification
uses: actions/github-script@v7
env:
TAG: ${{ steps.getSnapshotName.outputs.result }}
STATUS_DATA: ${{ steps.changesets.outputs.status }}
BUILD_LOG: ${{ steps.publish.outputs.build }}
PUBLISH_LOG: ${{ steps.publish.outputs.publish }}
with:
script: |
let changeset = { releases: [] };
try {
changeset = JSON.parse(process.env.STATUS_DATA);
} catch (e) {}
let message = 'Snapshots have been released for the following packages:'
for (const release of changeset.releases) {
if (release.type === 'none') continue;
message += `\n- \`${release.name}@experimental--${process.env.TAG}\``;
}
function details(title, body) {
message += '\n';
message += `<details><summary><strong>${title}</strong></summary>`
message += '\n\n```\n';
message += body;
message += '\n```\n\n</details>';
}
details('Publish Log', process.env.PUBLISH_LOG);
details('Build Log', process.env.BUILD_LOG);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message,
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "qwikdev-astro",
"version": "0.0.0",
"scripts": {},
"dependencies": {},
"devDependencies": {}
"dependencies": {
"@changesets/cli": "^2.27.1"
}
}
Loading

0 comments on commit 4c0c156

Please sign in to comment.