Skip to content

Continuous release with pkg.pr.new and esm.sh #9

Continuous release with pkg.pr.new and esm.sh

Continuous release with pkg.pr.new and esm.sh #9

name: Publish approved pull requests and latest commit to pkg.pr.new
on:
pull_request:
branches:
- 'dev-2.0'
push:
branches:
- 'dev-2.0'
tags:
- '!**'
permissions:
pull-requests: write
issues: write
jobs:
publish:
if: github.repository == 'processing/p5.js'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Build library
run: npm run build
- name: Publish library
run: npx pkg-pr-new publish --no-template --json output.json --comment=off
- name: Upload output data
uses: actions/upload-artifact@v4
with:
name: output.json
path: output.json
# - name: Post or update comment
# uses: actions/github-script@v8
# with:
# github-token: ${{ secrets.ACCESS_TOKEN }}
# script: |
# const fs = require('fs');
# const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
# const packages = output.packages
# .map((p) => `- ${p.name}: ${p.url}`)
# .join('\n');
# const cdnLinks = output.packages
# .map((p) => `- ${p.name}: https://raw.esm.sh/pr/p5@${p.sha}/lib/p5.min.js`)
# .join('\n');
# const sha =
# context.event_name === 'pull_request'
# ? context.payload.pull_request.head.sha
# : context.payload.after;
# const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`;
# const body = `## Continuous Release
# ### CDN link
# ${cdnLinks}
# ### Published Packages:
# ${packages}
# [View Commit](${commitUrl})
# ---
# _This is an automated message._`;
# const botCommentIdentifier = '## Continuous Release';
# async function findBotComment(issueNumber) {
# if (!issueNumber) return null;
# const comments = await github.rest.issues.listComments({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: issueNumber,
# });
# return comments.data.find((comment) =>
# comment.body.includes(botCommentIdentifier)
# );
# }
# async function createOrUpdateComment(issueNumber) {
# if (!issueNumber) {
# console.log('No issue number provided. Cannot post or update comment.');
# return;
# }
# const existingComment = await findBotComment(issueNumber);
# if (existingComment) {
# await github.rest.issues.updateComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# comment_id: existingComment.id,
# body: body,
# });
# } else {
# await github.rest.issues.createComment({
# issue_number: issueNumber,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: body,
# });
# }
# }
# async function logPublishInfo() {
# console.log('\n' + '='.repeat(50));
# console.log('Publish Information');
# console.log('='.repeat(50));
# console.log('\nPublished Packages:');
# console.log(packages);
# console.log('\nTemplates:');
# console.log(templates);
# console.log(`\nCommit URL: ${commitUrl}`);
# console.log('\n' + '='.repeat(50));
# }
# if (context.eventName === 'pull_request') {
# if (context.issue.number) {
# await createOrUpdateComment(context.issue.number);
# }
# } else if (context.eventName === 'push') {
# const pullRequests = await github.rest.pulls.list({
# owner: context.repo.owner,
# repo: context.repo.repo,
# state: 'open',
# head: `${context.repo.owner}:${context.ref.replace(
# 'refs/heads/',
# ''
# )}`,
# });
# if (pullRequests.data.length > 0) {
# await createOrUpdateComment(pullRequests.data[0].number);
# } else {
# console.log(
# 'No open pull request found for this push. Logging publish information to console:'
# );
# await logPublishInfo();
# }
# }