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
36 changes: 36 additions & 0 deletions .github/scripts/validate-pr-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @ts-check

const { readFileSync } = require('node:fs');

module.exports = main;

/**
*
* @param {{filePath:string}} options
* @returns {number}
*/
function main(options) {
return validatePrNumber(options.filePath);
}

/**
*
* @param {string} filePath
* @returns {number}
*/
function validatePrNumber(filePath) {
try {
const content = readFileSync(filePath, 'utf-8').trim();
const prNumber = Number(content);

if (isNaN(prNumber) || !Number.isInteger(prNumber)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: using Number.isInteger should enough since it also checks for NaN, making isNaN redundant.

throw new Error('The ID in pr.txt is not a valid PR number.');
}

console.info('✅ PR ID valid');
return prNumber;
} catch (err) {
console.error(`Error: ${err.message}`);
process.exit(1);
}
}
23 changes: 16 additions & 7 deletions .github/workflows/pr-website-deploy-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
outputs:
pr_number: ${{ steps.pr_number.outputs.id }}
pr_number: ${{ steps.pr_number.outputs.result }}
website_url: ${{ steps.website_url.outputs.id }}
permissions:
id-token: write

steps:
- name: Download WebSite artifacts
uses: actions/download-artifact@v4
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github

- uses: actions/download-artifact@v4
with:
name: pr-website-artifacts
path: ./website
Expand All @@ -41,13 +45,18 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Load PR number
uses: actions/github-script@v7
id: pr_number
run: echo "id=$(cat pr.txt)" >> $GITHUB_OUTPUT
working-directory: ./results
with:
script: |
const run = require('./.github/scripts/validate-pr-number');
const result = run({filePath:'results/pr.txt'});
return result;
result-encoding: string

- name: Load WEBSITE URL
id: website_url
run: echo "id=${{env.DEPLOY_HOST_URL}}pull/${{steps.pr_number.outputs.id}}/" >> $GITHUB_OUTPUT
run: echo "id=${{env.DEPLOY_HOST_URL}}pull/${{steps.pr_number.outputs.result}}/" >> $GITHUB_OUTPUT

- name: Login via Azure CLI
uses: azure/login@v2
Expand All @@ -67,7 +76,7 @@ jobs:
--destination '$web' \
--source ./website \
--account-name ${{ env.AZURE_STORAGE }} \
--destination-path pull/${{steps.pr_number.outputs.id}} \
--destination-path pull/${{steps.pr_number.outputs.result}} \
--auth-mode login \
--overwrite

Expand Down