Skip to content

Commit

Permalink
Merge pull request #372 from Infineon/371-bug-pr-preview-deployment-a…
Browse files Browse the repository at this point in the history
…ction-of-storybook-not-updating-comment-on-github-concurrency-issue

workflow bug fix
  • Loading branch information
tishoyanchev authored Aug 11, 2023
2 parents 85f5a90 + c5fa091 commit ea2c31a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/github_pages_storybook_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,35 @@ jobs:
run: |
echo "Preview URL: ${{ steps.preview.outputs.deployment-url }}"
- name: Update comment in PR
- name: Update comment in PR # add comment on github
uses: actions/github-script@v4
with:
script: |
const prNumber = context.payload.pull_request.number;
const STORYBOOK_IDENTIFIER = "--STORYBOOK-PREVIEW--";
const newText = `--STORYBOOK-PREVIEW--\n- PR Preview URL for Storybook: ${{ steps.preview.outputs.deployment-url }}`;
const {data: comments} = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const autoComment = comments.find(c => c.user.login === 'github-actions[bot]');
if (autoComment) {
const existingText = autoComment.body;
const newText = '\n- PR Preview URL for Storybook: ${{ steps.preview.outputs.deployment-url }}';
if (!existingText.includes(newText)) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: autoComment.id,
body: `${existingText}\n${newText}`
});
}
const storybookComment = comments.find(c => c.body.startsWith(STORYBOOK_IDENTIFIER));
if (storybookComment) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: storybookComment.id,
body: newText
});
} else {
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: newText
});
}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
25 changes: 12 additions & 13 deletions .github/workflows/shipit_pr_and_example_apps_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:
umbrella-dir: pr-preview-vanilla-example
token: ${{ secrets.GH_TOKEN }}

update-pr-comment:
update-pr-comment: # add comment on github
needs: [deploy-preview-vue, deploy-preview-react, deploy-preview-angular, deploy-preview-vanilla]
runs-on: ubuntu-latest
steps:
Expand All @@ -222,24 +222,23 @@ jobs:
const reactUrl = "${{ needs.deploy-preview-react.outputs.deployment-url }}";
const angularUrl = "${{ needs.deploy-preview-angular.outputs.deployment-url }}";
const vanillaUrl = "${{ needs.deploy-preview-vanilla.outputs.deployment-url }}";
const newText = `PR Preview URLs:\n- Vue example: ${vueUrl}\n- React example: ${reactUrl}\n- Angular example: ${angularUrl}\n- Vanilla example: ${vanillaUrl}`;
const EXAMPLE_APPS_IDENTIFIER = "--EXAMPLE-APPS-PREVIEW--";
const newText = `--EXAMPLE-APPS-PREVIEW--\nPR Preview URLs:\n- Vue example: ${vueUrl}\n- React example: ${reactUrl}\n- Angular example: ${angularUrl}\n- Vanilla example: ${vanillaUrl}`;
const {data: comments} = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const autoComment = comments.find(c => c.user.login === 'github-actions[bot]');
if (autoComment) {
const existingText = autoComment.body;
if (!existingText.includes(newText)) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: autoComment.id,
body: `${existingText}\n${newText}`
});
}
const appsComment = comments.find(c => c.body.startsWith(EXAMPLE_APPS_IDENTIFIER));

if (appsComment) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: appsComment.id,
body: newText
});
} else {
await github.issues.createComment({
owner: context.repo.owner,
Expand Down

0 comments on commit ea2c31a

Please sign in to comment.