Skip to content

Commit

Permalink
Merge pull request #446 from hashicorp/ds.canary-releases
Browse files Browse the repository at this point in the history
feat: add support for canary releases
  • Loading branch information
dstaley authored Mar 13, 2024
2 parents 995a3b2 + bab00c7 commit da4412a
Show file tree
Hide file tree
Showing 5 changed files with 5,171 additions and 180 deletions.
14 changes: 14 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "hashicorp/next-mdx-remote" }
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
76 changes: 76 additions & 0 deletions .github/workflows/canary-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Canary Release

on:
workflow_call:
secrets:
CHANGESETS_PAT:
required: true
NPM_TOKEN:
required: true
pull_request:
types:
- opened
- synchronize
- reopened
- labeled

jobs:
release-canary:
name: Release Canary
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'release:canary')
steps:
- name: Checkout Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 18.x

- name: Install Dependencies
run: npm ci

- name: Version
run: npx changeset version --snapshot canary
env:
GITHUB_TOKEN: ${{ secrets.CHANGESETS_PAT }}

- name: Publish Canary Packages
id: changesets
uses: changesets/action@e2f8e964d080ae97c874b19e27b12e0a8620fb6c # v1.4.6
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: npm run release:canary
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.CHANGESETS_PAT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Compute new packages info
id: packagesData
if: success() && steps.changesets.outputs.published == 'true'
# We're using the special GH Actions syntax to add step outputs (ref: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter)
# for count: use jq to determine the length of the array
# for packageList: use jq reduce to build up a string of markdown (ref: https://stedolan.github.io/jq/manual/#Reduce)
run: |
echo "::set-output name=count::$(echo ${{toJson(steps.changesets.outputs.publishedPackages)}} | jq '. | length')"
echo "::set-output name=packageList::$(echo ${{toJson(steps.changesets.outputs.publishedPackages)}} | jq 'reduce .[] as $item (""; . + "#### \($item.name)@\($item.version)\n```\nnpm install \($item.name)@canary\n```\n")')"
- name: Comment
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
if: success() && steps.changesets.outputs.published == 'true'
with:
header: 'canary-release'
message: |
### :package: Canary Packages Published
Latest commit: ${{ github.event.pull_request.head.sha }}
<details><summary>Published ${{ steps.packagesData.outputs.count }} packages</summary>
${{ fromJSON(steps.packagesData.outputs.packageList) }}
</details>
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '16.x'
node-version: '18.x'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install and build
Expand Down
Loading

0 comments on commit da4412a

Please sign in to comment.