From 04ba58a46a5def0a928f29c6a59364a892caf189 Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Thu, 1 Aug 2024 21:07:58 -0700 Subject: [PATCH] trying out pkg.pr.new (#111) --- .github/workflows/external-pr-labeler.yaml | 40 ++++++++++++++++++++++ .github/workflows/release-preview.yaml | 25 ++++++++++++++ .github/workflows/release.yaml | 14 ++++---- .gitignore | 2 ++ package.json | 7 ++-- scripts/release-preview.js | 32 +++++++++++++++++ 6 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/external-pr-labeler.yaml create mode 100644 .github/workflows/release-preview.yaml create mode 100644 scripts/release-preview.js diff --git a/.github/workflows/external-pr-labeler.yaml b/.github/workflows/external-pr-labeler.yaml new file mode 100644 index 00000000..ae417d66 --- /dev/null +++ b/.github/workflows/external-pr-labeler.yaml @@ -0,0 +1,40 @@ +# thanks to https://github.com/systeminit/si/blob/main/.github/workflows/community-check.yml + +name: Label community PR + +on: + pull_request_target: + types: + - opened + - synchronize + - reopened + +jobs: + check-is-community: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + env: + DMNO_STAFF: "theoephraim philmillman" + steps: + - name: Check PR author + id: check_author + run: | + PR_AUTHOR="${{ github.event.pull_request.user.login }}" + if ! [[ "${DMNO_STAFF}" =~ "$PR_AUTHOR" ]]; then + echo "Authored by DMNO community member!" + echo "requires-community-tag=true" >> $GITHUB_OUTPUT + else + echo "Authored by DMNO staff" + fi + - name: Label PR + uses: actions/github-script@v5 + with: + script: | + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + labels: [ steps.check_author.outputs.requires-community-tag && 'community' && 'staff' ] + }); diff --git a/.github/workflows/release-preview.yaml b/.github/workflows/release-preview.yaml new file mode 100644 index 00000000..827d3bd0 --- /dev/null +++ b/.github/workflows/release-preview.yaml @@ -0,0 +1,25 @@ +name: Release preview packages +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Enable Corepack + run: corepack enable + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: "20.x" + cache: 'pnpm' + - name: Install node deps + run: pnpm i + + - name: Build + run: pnpm build:libs + + # we use a custom script to run `npx pkg-pr-new publish` + # so that we can determine which packages to release + - run: node scripts/release-preview.js diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8b9d94e5..136b8879 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,22 +13,24 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Install pnpm - uses: pnpm/action-setup@v4 - - name: Use Node.js + - name: Enable Corepack + run: corepack enable + - name: Use Node.js 20.x uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: "20.x" cache: 'pnpm' - - name: Install pnpm deps + - name: Install node deps run: pnpm i - name: Create Release Pull Request or Publish to npm id: changesets uses: changesets/action@v1 with: + title: "[Changesets] Versioned release" + commit: "[Changesets] Create versioned packages for publishing" # This expects you to have a script called release which does a build for your packages and calls changeset publish - publish: pnpm run build && pnpm run changeset:publish + publish: pnpm run changeset:publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index d9ed9ada..50d02ebc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ config.local.ts tmp-package-registry +changesets-summary.json + # DMNO files ### # local cache for resolved values **/.dmno/cache.json diff --git a/package.json b/package.json index a12297c3..8836a6af 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "root", "version": "0.0.0", "private": true, + "type": "module", "repository": { "type": "git", "url": "https://github.com/dmno-dev/core.git" @@ -26,8 +27,8 @@ "typescript": "^5.4.5" }, "engines": { - "node": "^18.17.1 || ^20.3.0 || >=21.0.0", - "pnpm": ">=9.1.1" + "node": "^20.3.0 || >=21.0.0", + "pnpm": ">=9.6.0" }, - "packageManager": "pnpm@9.1.1" + "packageManager": "pnpm@9.6.0" } diff --git a/scripts/release-preview.js b/scripts/release-preview.js new file mode 100644 index 00000000..fc44d363 --- /dev/null +++ b/scripts/release-preview.js @@ -0,0 +1,32 @@ +import { execSync } from 'node:child_process'; +import fs from 'node:fs'; + +let err; +try { + // pnpm m ls --json --depth=-1 | node -e "const path = require('path'); console.log(JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf-8')).map((m) => path.relative(__dirname, m.path)).filter(Boolean))" + const workspacePackagesInfoRaw = execSync('pnpm m ls --json --depth=-1'); + const workspacePackagesInfo = JSON.parse(workspacePackagesInfoRaw); + // console.log(workspacePackagesInfo); + + // generate sumamry of changed (publishable) modules according to changesets + // only has option to output to a file + execSync('pnpm exec changeset status --output=changesets-summary.json'); + + const changeSetsSummaryRaw = fs.readFileSync('./changesets-summary.json', 'utf8'); + const changeSetsSummary = JSON.parse(changeSetsSummaryRaw); + // console.log(changeSetsSummary); + + const releasePackagePaths = changeSetsSummary.releases + .filter((r) => r.newVersion !== r.oldVersion) + .map((r) => workspacePackagesInfo.find((p) => p.name === r.name)) + .map((p) => p.path); + // console.log(releasePackagePaths); + + execSync(`pnpm dlx pkg-pr-new publish --compact ${releasePackagePaths.join(' ')}`); +} catch (_err) { + err = _err; + console.error('preview release failed'); + console.error(_err); +} +fs.unlinkSync('./changesets-summary.json'); +process.exit(err ? 1 : 0);