Skip to content
Open
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
171 changes: 170 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:

outputs:
published: ${{ steps.check-changes.outputs.has_changes }}
package_versions: ${{ steps.increment.outputs.package_versions }}

steps:
- name: Checkout Project
Expand Down Expand Up @@ -126,10 +127,19 @@ jobs:
echo "npmAuthToken: ${{ env.token }}" >> ~/.yarnrc.yml

- name: Sync and Increment Package Versions
id: increment
if: steps.check-changes.outputs.has_changes == 'true'
run: |
yarn package-tools sync --tag ${GITHUB_REF##*/}
yarn package-tools increment --packages ${{ needs.analyze-changes.outputs.node-recursive }} --tag ${GITHUB_REF##*/}
OUTPUT=$(yarn package-tools increment --packages ${{ needs.analyze-changes.outputs.node-recursive }} --tag ${GITHUB_REF##*/})
echo "$OUTPUT"
echo "package_versions<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" | while IFS= read -r line; do
if echo "$line" | grep -q ' => '; then
echo "__webex_release__: $line"
fi
done >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build Changed Packages
if: steps.check-changes.outputs.has_changes == 'true'
run: yarn run build:prod
Expand Down Expand Up @@ -348,3 +358,162 @@ jobs:
echo "=========================================="
echo "Tagging complete!"
echo "=========================================="

comment-on-pr:
name: Comment on Released PRs
needs: [publish-npm, publish-tag]
runs-on: ubuntu-latest

steps:
- name: Get PR Number
id: get-pr
uses: actions/github-script@v7
with:
script: |
const deploySha = context.sha;
const owner = 'webex';
const repo = 'widgets';

try {
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner, repo, commit_sha: deploySha
});
const mergedPR = prs.data.find(pr => pr.merged_at);
if (mergedPR) {
core.setOutput('pr_number', String(mergedPR.number));
return;
}
} catch (error) {
console.log(`Failed to discover PR from commit: ${error.message}`);
}
core.setOutput('pr_number', '');

- name: Post Release Comment on PR
if: steps.get-pr.outputs.pr_number != ''
uses: actions/github-script@v7
with:
script: |
const prNumber = parseInt('${{ steps.get-pr.outputs.pr_number }}');

const raw = `${{ needs.publish-npm.outputs.package_versions }}`;
const packageVersions = {};
for (const line of raw.split('\n')) {
const match = line.match(/^__webex_release__:\s+(.+?)\s+=>\s+(.+)$/);
if (match) packageVersions[match[1].trim()] = match[2].trim();
}
const packageEntries = Object.entries(packageVersions);

const owner = 'webex';
const repo = 'widgets';
const repoUrl = `https://github.com/${owner}/${repo}`;
const hasPackages = packageEntries.length > 0;

const taggablePackages = {
'@webex/widgets': 'webex-widgets',
'@webex/cc-widgets': 'webex-cc-widgets'
};

let commentBody;

if (hasPackages) {
const tagLinks = Object.entries(taggablePackages)
.filter(([pkg]) => packageVersions[pkg])
.map(([pkg, prefix]) => {
const tag = `${prefix}-v${packageVersions[pkg]}`;
return `[\`${tag}\`](${repoUrl}/releases/tag/${tag})`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Link pushed tags to tag pages instead of releases

The PR comment builds tag links as .../releases/tag/${tag}, but in the workflows I inspected this pipeline only creates and pushes Git tags (no GitHub Release creation step). In that setup, releases/tag/... URLs can point to missing release pages, so the “Released in” links in the comment break for contributors. Point to tag URLs (for example /tree/${tag} or /tags) or create releases before using release URLs.

Useful? React with 👍 / 👎.

})
.join(', ');

const releaseLine = tagLinks
? `**Released in:** ${tagLinks}`
: '';

const changelogBaseUrl = 'https://widgets.webex.com/changelog/';
const aggregators = ['@webex/cc-widgets', '@webex/widgets'];
const changelogPkg = aggregators.find(p => packageVersions[p])
|| packageEntries[0]?.[0];
let changelogLine = '';
if (changelogPkg) {
const ver = packageVersions[changelogPkg];
const stableVersion = ver.replace(/-.*$/, '');
const url = `${changelogBaseUrl}?stable_version=${stableVersion}&package=${encodeURIComponent(changelogPkg)}&version=${encodeURIComponent(ver)}`;
changelogLine = `:book: **[View full changelog](${url})**`;
}

const rows = packageEntries
.sort(([a], [b]) => {
if (a === '@webex/cc-widgets') return -1;
if (b === '@webex/cc-widgets') return 1;
if (a === '@webex/widgets') return -1;
if (b === '@webex/widgets') return 1;
return a.localeCompare(b);
})
.map(([pkg, ver]) => `| \`${pkg}\` | \`${ver}\` |`)
.join('\n');

const packagesTable = [
'',
'| Packages Updated | Version |',
'|---------|---------|',
rows,
''
].join('\n');

commentBody = [
':tada: **Your changes are now available!**',
'',
releaseLine,
changelogLine,
packagesTable,
'Thank you for your contribution!',
'',
`_:robot: This is an automated message. For questions, please refer to the [documentation](${repoUrl}#readme)._`
].filter(Boolean).join('\n');
} else {
commentBody = [
':white_check_mark: **Your changes have been merged!**',
'',
'Thank you for your contribution!',
'',
`_:robot: This is an automated message. For questions, please refer to the [documentation](${repoUrl}#readme)._`
].join('\n');
}

try {
const pr = await github.rest.pulls.get({ owner, repo, pull_number: prNumber });
if (!pr.data.merged_at) return;

const existingComments = await github.rest.issues.listComments({
owner, repo,
issue_number: prNumber,
per_page: 100
});

const detailedComment = existingComments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Your changes are now available')
);
const mergedComment = existingComments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Your changes have been merged')
);

if (detailedComment) return;
if (!hasPackages && mergedComment) return;

if (mergedComment && hasPackages) {
await github.rest.issues.updateComment({
owner, repo,
comment_id: mergedComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
owner, repo,
issue_number: prNumber,
body: commentBody
});
}
} catch (error) {
core.warning(`Failed to comment on PR #${prNumber}: ${error.message}`);
}