Skip to content

Commit

Permalink
tryng out pkg.pr.new (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoephraim authored Aug 2, 2024
1 parent 3483b9a commit bfde2d7
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 8 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/external-pr-labeler.yaml
Original file line number Diff line number Diff line change
@@ -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' ]
});
25 changes: 25 additions & 0 deletions .github/workflows/release-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish Any Commit
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

# 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
10 changes: 5 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ config.local.ts

tmp-package-registry

changesets-summary.json

# DMNO files ###
# local cache for resolved values
**/.dmno/cache.json
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
32 changes: 32 additions & 0 deletions scripts/release-preview.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit bfde2d7

Please sign in to comment.