Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/npm-publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ jobs:
# Get the current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")

# Generate a timestamp for uniqueness
TIMESTAMP=$(date +"%Y%m%d%H%M%S")

# For PR: use PR number in version
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BETA_VERSION="$CURRENT_VERSION-beta.pr.${{ github.event.pull_request.number }}"
BETA_VERSION="$CURRENT_VERSION-beta.pr.${{ github.event.pull_request.number }}.$TIMESTAMP"
else
# For develop: use commit hash
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
BETA_VERSION="$CURRENT_VERSION-beta.$SHORT_SHA"
BETA_VERSION="$CURRENT_VERSION-beta.$SHORT_SHA.$TIMESTAMP"
fi

# Set output for use in next step
Expand All @@ -51,3 +54,22 @@ jobs:
run: npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Comment on PR with published version
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const version = process.env.BETA_VERSION;
const packageName = '@space48/sdm';
const installCmd = `npm install ${packageName}@${version}`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 Beta version published: **${version}**\n\nYou can install this version with:\n\`\`\`bash\n${installCmd}\n\`\`\``
});
env:
BETA_VERSION: ${{ steps.beta-version.outputs.version }}
41 changes: 41 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,48 @@ jobs:
- name: Build
run: npm run build

- name: Get package version
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Find related PRs and comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const version = process.env.PACKAGE_VERSION;
const packageName = '@space48/sdm';
const installCmd = `npm install ${packageName}@${version}`;

// Get the commit message to find PR number
const { data: commit } = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha
});

// Look for PR references in the commit message (like "Merge pull request #123")
const prMatch = commit.commit.message.match(/Merge pull request #(\d+)/i);

if (prMatch && prMatch[1]) {
const prNumber = parseInt(prMatch[1], 10);

// Comment on the PR
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 New version published: **${version}**\n\nThis version has been published to npm and is now available.\n\nYou can install it with:\n\`\`\`bash\n${installCmd}\n\`\`\``
});

console.log(`Commented on PR #${prNumber} about the new release ${version}`);
} else {
console.log('No PR reference found in the commit message. Skipping comment.');
}
env:
PACKAGE_VERSION: ${{ steps.package-version.outputs.version }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@space48/json-pipe",
"version": "0.4.15",
"version": "0.4.16",
"description": "A tiny library for creating JSON pipeline CLI programs",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down