From cb6e45a3bc960af6d1eb8aae12c0f4b240bb4322 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 19 Oct 2022 15:52:39 +0200 Subject: [PATCH] Prepare for release (#9605) * rename `build-cli.yml` to `prepare-release.yml` In other repo's we will also have a `prepare-release` so this makes it a bit more consistent. * use common CONSTANT_CASE for environment variables * use `strategy` for defining the node version * add script to get the release notes * add release notes to release draft * use CONSTANT_CASE for environment variables * improve consistency for relase related scripts --- .../{build-cli.yml => prepare-release.yml} | 39 +++++++++++++------ .github/workflows/release-insiders.yml | 8 ++-- .github/workflows/release.yml | 10 ++--- package.json | 3 +- scripts/calculate-tag-name.js | 8 ---- scripts/release-channel.js | 18 +++++++++ scripts/release-notes.js | 21 ++++++++++ 7 files changed, 77 insertions(+), 30 deletions(-) rename .github/workflows/{build-cli.yml => prepare-release.yml} (64%) delete mode 100644 scripts/calculate-tag-name.js create mode 100644 scripts/release-channel.js create mode 100644 scripts/release-notes.js diff --git a/.github/workflows/build-cli.yml b/.github/workflows/prepare-release.yml similarity index 64% rename from .github/workflows/build-cli.yml rename to .github/workflows/prepare-release.yml index 7e47eadf9..6dfeb3a84 100644 --- a/.github/workflows/build-cli.yml +++ b/.github/workflows/prepare-release.yml @@ -1,4 +1,4 @@ -name: Build Standalone CLI +name: Prepare Release on: workflow_dispatch: @@ -13,10 +13,16 @@ permissions: contents: read jobs: - build_cli: + build: permissions: contents: write # for softprops/action-gh-release to create GitHub release + runs-on: macos-11 + + strategy: + matrix: + node-version: [16] + steps: - uses: actions/checkout@v3 @@ -25,12 +31,19 @@ jobs: - name: Resolve version id: vars run: | - echo "tag_name=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + echo "TAG_NAME=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV - - name: Use Node.js 16 + - name: Get release notes + run: | + RELEASE_NOTES=$(npm run release-notes --silent) + echo "RELEASE_NOTES<> $GITHUB_ENV + echo "$RELEASE_NOTES" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: - node-version: '16' + node-version: ${{ matrix.node-version }} registry-url: 'https://registry.npmjs.org' - name: Build tailwindcss @@ -52,14 +65,16 @@ jobs: uses: softprops/action-gh-release@v1 with: draft: true - tag_name: ${{ env.tag_name }} + tag_name: ${{ env.TAG_NAME }} body: | - * [Linux (arm64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.tag_name }}/tailwindcss-linux-arm64) - * [Linux (armv7)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.tag_name }}/tailwindcss-linux-armv7) - * [Linux (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.tag_name }}/tailwindcss-linux-x64) - * [macOS (arm64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.tag_name }}/tailwindcss-macos-arm64) - * [macOS (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.tag_name }}/tailwindcss-macos-x64) - * [Windows (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.tag_name }}/tailwindcss-windows-x64.exe) + ${{ env.RELEASE_NOTES }} + + * [Linux (arm64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.TAG_NAME }}/tailwindcss-linux-arm64) + * [Linux (armv7)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.TAG_NAME }}/tailwindcss-linux-armv7) + * [Linux (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.TAG_NAME }}/tailwindcss-linux-x64) + * [macOS (arm64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.TAG_NAME }}/tailwindcss-macos-arm64) + * [macOS (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.TAG_NAME }}/tailwindcss-macos-x64) + * [Windows (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ env.TAG_NAME }}/tailwindcss-windows-x64.exe) files: | standalone-cli/dist/tailwindcss-linux-arm64 standalone-cli/dist/tailwindcss-linux-armv7 diff --git a/.github/workflows/release-insiders.yml b/.github/workflows/release-insiders.yml index a55883a22..2e55b18d7 100644 --- a/.github/workflows/release-insiders.yml +++ b/.github/workflows/release-insiders.yml @@ -61,10 +61,10 @@ jobs: - name: Resolve version id: vars run: | - echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: 'Version based on commit: 0.0.0-insiders.${{ env.sha_short }}' - run: npm version 0.0.0-insiders.${{ env.sha_short }} --force --no-git-tag-version + - name: 'Version based on commit: 0.0.0-insiders.${{ env.SHA_SHORT }}' + run: npm version 0.0.0-insiders.${{ env.SHA_SHORT }} --force --no-git-tag-version - name: Publish run: npm publish --tag insiders @@ -83,6 +83,6 @@ jobs: ref: 'master', workflow_id: 'upgrade-tailwindcss.yml', inputs: { - insidersVersion: '0.0.0-insiders.${{ env.sha_short }}' + insidersVersion: '0.0.0-insiders.${{ env.SHA_SHORT }}' } }) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e54466bdb..dbd03894a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,17 +47,17 @@ jobs: - name: Calculate environment variables run: | - echo "tag_name=$(npm run calculate-tag-name --silent)" >> $GITHUB_ENV - echo "tailwindcss_version=$(node -e 'console.log(require(`./package.json`).version);')" >> $GITHUB_ENV + echo "RELEASE_CHANNEL=$(npm run release-channel --silent)" >> $GITHUB_ENV + echo "TAILWINDCSS_VERSION=$(node -e 'console.log(require(`./package.json`).version);')" >> $GITHUB_ENV - name: Publish - run: npm publish --tag ${{ env.tag_name }} + run: npm publish --tag ${{ env.RELEASE_CHANNEL }} env: CI: true NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Trigger Tailwind Play update - if: env.tag_name == 'latest' + if: env.RELEASE_CHANNEL == 'latest' uses: actions/github-script@v6 with: github-token: ${{ secrets.TAILWIND_PLAY_TOKEN }} @@ -68,6 +68,6 @@ jobs: ref: 'master', workflow_id: 'upgrade-tailwindcss.yml', inputs: { - version: '${{ env.tailwindcss_version }}' + version: '${{ env.TAILWINDCSS_VERSION }}' } }) diff --git a/package.json b/package.json index 645128fd4..9486e39d7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "generate:plugin-list": "node -r @swc/register scripts/create-plugin-list.js", "generate:types": "node -r @swc/register scripts/generate-types.js", "generate": "npm run generate:plugin-list && npm run generate:types", - "calculate-tag-name": "node scripts/calculate-tag-name.js" + "release-channel": "node ./scripts/release-channel.js", + "release-notes": "node ./scripts/release-notes.js" }, "files": [ "src/*", diff --git a/scripts/calculate-tag-name.js b/scripts/calculate-tag-name.js deleted file mode 100644 index 7d9cd7939..000000000 --- a/scripts/calculate-tag-name.js +++ /dev/null @@ -1,8 +0,0 @@ -let version = process.env.npm_package_version || require('../package.json').version - -let match = /\d+\.\d+\.\d+-(.*)\.\d+/g.exec(version) -if (match) { - console.log(match[1]) -} else { - console.log('latest') -} diff --git a/scripts/release-channel.js b/scripts/release-channel.js new file mode 100644 index 000000000..0c827f3fd --- /dev/null +++ b/scripts/release-channel.js @@ -0,0 +1,18 @@ +// Given a version, figure out what the release channel is so that we can publish to the correct +// channel on npm. +// +// E.g.: +// +// 1.2.3 -> latest (default) +// 0.0.0-insiders.ffaa88 -> insiders +// 4.1.0-alpha.4 -> alpha + +let version = + process.argv[2] || process.env.npm_package_version || require('../package.json').version + +let match = /\d+\.\d+\.\d+-(.*)\.\d+/g.exec(version) +if (match) { + console.log(match[1]) +} else { + console.log('latest') +} diff --git a/scripts/release-notes.js b/scripts/release-notes.js new file mode 100644 index 000000000..bd29e952d --- /dev/null +++ b/scripts/release-notes.js @@ -0,0 +1,21 @@ +// Given a version, figure out what the release notes are so that we can use this to pre-fill the +// relase notes on a GitHub release for the current version. + +let path = require('path') +let fs = require('fs') + +let version = + process.argv[2] || process.env.npm_package_version || require('../package.json').version + +let changelog = fs.readFileSync(path.resolve(__dirname, '..', 'CHANGELOG.md'), 'utf8') +let match = new RegExp( + `## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`, + 'g' +).exec(changelog) + +if (match) { + let [, , notes] = match + console.log(notes.trim()) +} else { + console.log(`Placeholder release notes for version: v${version}`) +}