-
Notifications
You must be signed in to change notification settings - Fork 109
fix: link to test preview #1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
b5eea1a
to
aadd57d
Compare
dafc916
to
6937693
Compare
c41dc32
to
8b65e52
Compare
794239c
to
194b175
Compare
a80250a
to
02836a2
Compare
Hi @NoamGaash The issue with this bug fix is that I am trying to resolve a race condition between 2 different workflows. This is how I see the flow: 1.PR is created/updated My solution includes: First, I tried to add a step that waits for the validate to finish before trying to reach out to the artifacts but it seems not to work for some reason. WDYT? |
Thanks! That's ok if the link will be posted before the results are available, as long as the link will be correct once the results are uploaded. Is that what you mean? |
02836a2
to
4dfd3d1
Compare
30c71ff
to
3b7f251
Compare
1011020
to
679c2c9
Compare
679c2c9
to
c9db3ec
Compare
9515aad
to
c449a15
Compare
c449a15
to
c31ba0a
Compare
84173d1
to
15f6610
Compare
15f6610
to
e25493d
Compare
a5132e0
to
43bd25a
Compare
.github/workflows/deploy-preview.yml
Outdated
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Debug Workflow Info | ||
run: | | ||
echo "=== Workflow Debug Info ===" | ||
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}" | ||
echo "Run Number: ${{ github.event.workflow_run.run_number }}" | ||
echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" | ||
echo "Head Branch: ${{ github.event.workflow_run.head_branch }}" | ||
echo "Repository: ${{ github.repository }}" | ||
|
||
- name: Download dist-build artifact | ||
uses: dawidd6/action-download-artifact@v9 | ||
with: | ||
workflow: Build | ||
name: dist-build | ||
path: . | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
pr: ${{ github.event.workflow_run.pull_requests[0].number }} | ||
|
||
|
||
- name: Download dist-storybook artifact | ||
uses: dawidd6/action-download-artifact@v9 | ||
with: | ||
workflow: 'Build' | ||
workflow_conclusion: success | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
run_id: ${{ github.event.workflow_run.id }} | ||
run_number: ${{ github.event.workflow_run.run_number }} | ||
name: dist-storybook | ||
path: storybook | ||
|
||
- name: Download pr number | ||
uses: dawidd6/action-download-artifact@v9 | ||
with: | ||
workflow: 'Build' | ||
workflow_conclusion: success | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
run_id: ${{ github.event.workflow_run.id }} | ||
run_number: ${{ github.event.workflow_run.run_number }} | ||
name: pr_number | ||
path: . | ||
|
||
- name: Read and sanitize PR number | ||
id: read-pr | ||
run: | | ||
pr_number=$(cat pr_number | tr -d '\n' | grep -E '^[0-9]+$' || echo "") | ||
if [ -z "$pr_number" ]; then | ||
echo "Error: Invalid PR number" >&2 | ||
exit 1 | ||
fi | ||
echo "PR_NUMBER=${pr_number}" >> $GITHUB_ENV | ||
|
||
- uses: shallwefootball/s3-upload-action@master | ||
name: Upload preview to S3 | ||
if: always() | ||
id: s3-trace | ||
continue-on-error: true | ||
with: | ||
aws_key_id: ${{ secrets.AWS_KEY_ID }} | ||
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws_bucket: noam-gaash.co.il | ||
source_dir: . # Upload the root directory | ||
destination_dir: ${{ github.event.workflow_run.id }}/open-bus/${{ github.event.workflow_run.run_number }} | ||
|
||
- name: find comment | ||
uses: peter-evans/find-comment@v3 | ||
if: env.PR_NUMBER | ||
id: fc | ||
with: | ||
issue-number: ${{ env.PR_NUMBER }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: 'Preview' | ||
|
||
- name: update comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
if: steps.fc.outputs.comment-id | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
edit-mode: replace | ||
body: | | ||
Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.event.workflow_run.id }}/open-bus/${{ github.event.workflow_run.run_number }}/index.html | ||
Preview Storybook: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.event.workflow_run.id }}/open-bus/${{ github.event.workflow_run.run_number }}/storybook/index.html | ||
Test Report (if available): https://s3.amazonaws.com/noam-gaash.co.il/${{ github.event.workflow_run.id }}/open-bus/test_03/test-results/index.html | ||
|
||
- name: create comment | ||
uses: peter-evans/create-or-update-comment@v4 | ||
if: steps.fc.outputs.comment-id == '' | ||
with: | ||
issue-number: ${{ env.PR_NUMBER }} | ||
body: | | ||
Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.event.workflow_run.id }}/open-bus/${{ github.event.workflow_run.run_number }}/index.html | ||
Preview Storybook: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.event.workflow_run.id }}/open-bus/${{ github.event.workflow_run.run_number }}/storybook/index.html | ||
Test Report (if available): https://s3.amazonaws.com/noam-gaash.co.il/${{ github.event.workflow_run.id }}/open-bus/test_03/test-results/index.html | ||
|
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the issue, we need to add a permissions
block to the workflow file. This block should specify the minimal permissions required for the workflow to function correctly. Based on the actions performed in the workflow, the following permissions are needed:
contents: read
- To interact with repository contents, such as downloading artifacts.issues: write
- To create or update comments on pull requests.pull-requests: read
- To access pull request details.
The permissions
block can be added at the root level of the workflow file to apply to all jobs, or it can be added specifically to the deploy-to-s3
job.
-
Copy modified lines R1-R15
@@ -1,11 +1,16 @@ | ||
on: | ||
workflow_run: | ||
workflows: ['Build'] | ||
types: | ||
- completed | ||
push: | ||
|
||
jobs: | ||
deploy-to-s3: | ||
runs-on: ubuntu-latest | ||
on: | ||
workflow_run: | ||
workflows: ['Build'] | ||
types: | ||
- completed | ||
push: | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: read | ||
|
||
jobs: | ||
deploy-to-s3: | ||
runs-on: ubuntu-latest | ||
steps: |
43bd25a
to
d7f1a71
Compare
d7f1a71
to
ec7b5a2
Compare
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}" | ||
echo "Run Number: ${{ github.event.workflow_run.run_number }}" | ||
echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" | ||
echo "Head Branch: ${{ github.event.workflow_run.head_branch }}" |
Check failure
Code scanning / CodeQL
Code injection Critical
${ github.event.workflow_run.head_branch }
workflow_run
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the issue, we will:
- Assign the value of
${{ github.event.workflow_run.head_branch }}
to an intermediate environment variable. - Use the environment variable in the shell script with proper shell syntax (
"$VAR"
), which prevents code injection by treating the value as a literal string.
This approach ensures that the input is safely passed to the shell without the risk of unintended command execution.
-
Copy modified lines R22-R23
@@ -21,3 +21,4 @@ | ||
echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" | ||
echo "Head Branch: ${{ github.event.workflow_run.head_branch }}" | ||
HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" | ||
echo "Head Branch: $HEAD_BRANCH" | ||
else |
run: | | ||
echo "=== Workflow Debug Info ===" | ||
echo "Event name: ${{ github.event_name }}" | ||
if [ "${{ github.event_name }}" = "workflow_run" ]; then | ||
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}" | ||
echo "Run Number: ${{ github.event.workflow_run.run_number }}" | ||
echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" | ||
echo "Head Branch: ${{ github.event.workflow_run.head_branch }}" | ||
else | ||
echo "Push event details:" | ||
echo "SHA: ${{ github.sha }}" | ||
echo "Ref: ${{ github.ref }}" | ||
echo "Branch: ${{ github.ref_name }}" | ||
fi | ||
echo "Repository: ${{ github.repository }}" |
Check failure
Code scanning / CodeQL
Expression injection in Actions Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the issue, we will follow the recommended best practice of using environment variables and shell-native syntax to safely handle user-controlled input. Specifically, we will:
- Set the value of
${{ github.event.workflow_run.head_branch }}
to an intermediate environment variable. - Use the environment variable in the shell command with native syntax (
$VAR
) instead of expression syntax (${{ env.VAR }}
).
This approach ensures that the input is treated as a literal string by the shell, preventing injection attacks.
-
Copy modified lines R18-R20 -
Copy modified lines R24-R25 -
Copy modified line R88
@@ -17,3 +17,5 @@ | ||
echo "Event name: ${{ github.event_name }}" | ||
if [ "${{ github.event_name }}" = "workflow_run" ]; then | ||
if [ "${{ github.event_name }}" = "workflow_run" ]; then | ||
export WORKFLOW_RUN_ID="${{ github.event.workflow_run.id }}" | ||
export WORKFLOW_RUN_NUMBER="${{ github.event.workflow_run.run_number }}" | ||
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}" | ||
@@ -21,3 +23,4 @@ | ||
echo "Head SHA: ${{ github.event.workflow_run.head_sha }}" | ||
echo "Head Branch: ${{ github.event.workflow_run.head_branch }}" | ||
export HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" | ||
echo "Head Branch: $HEAD_BRANCH" | ||
else | ||
@@ -84,3 +87,3 @@ | ||
source_dir: . # Upload the root directory | ||
destination_dir: ${{ github.event.workflow_run.id }}/open-bus/${{ github.event.workflow_run.run_number }} | ||
destination_dir: ${{ env.WORKFLOW_RUN_ID }}/open-bus/${{ env.WORKFLOW_RUN_NUMBER }} | ||
|
Description
Fix the broken link to test preview. The fix was made by changing some parts of the URL to consistent values in both workflows of the CI. We create 2 variables in one workflow and by uploading them to artifact we could access them in another workflow.