From 58a26fb6411ecbb9be59521e412d7c92e51ef283 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 12 Dec 2023 10:10:04 -0800 Subject: [PATCH 1/3] tryit --- eng/pipelines/pr-tryit.yml | 5 +++++ eng/scripts/create-tryit-comment.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/pr-tryit.yml b/eng/pipelines/pr-tryit.yml index fcb2be7690..4ac394283c 100644 --- a/eng/pipelines/pr-tryit.yml +++ b/eng/pipelines/pr-tryit.yml @@ -47,3 +47,8 @@ jobs: --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ --source "./packages/website/build/" \ --overwrite + + - script: node eng/scripts/create-tryit-comment.js "cadl-azure" + displayName: Check already commented + env: + GH_TOKEN: $(azuresdk-github-pat) diff --git a/eng/scripts/create-tryit-comment.js b/eng/scripts/create-tryit-comment.js index 641bc94802..d41df72ad1 100644 --- a/eng/scripts/create-tryit-comment.js +++ b/eng/scripts/create-tryit-comment.js @@ -26,7 +26,10 @@ async function main() { const folderName = process.argv.length > 2 ? `/${process.argv[2]}` : ""; const repo = process.env["BUILD_REPOSITORY_ID"]; const prNumber = process.env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"]; - const ghAuth = getGithubAuthHeader(repo); + const ghAuth = process.env.GH_TOKEN; + if (ghAuth === undefined) { + throw new Error("GH_TOKEN environment variable is not set"); + } console.log("Looking for comments in", { repo, prNumber }); const data = await listComments(repo, prNumber, ghAuth); From c363c3c11ba4e974256d9abd5794ddbc79b69f49 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 12 Dec 2023 10:26:28 -0800 Subject: [PATCH 2/3] test --- eng/pipelines/pr-tryit.yml | 50 ++++++++++++++--------------- eng/scripts/create-tryit-comment.js | 5 +-- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/eng/pipelines/pr-tryit.yml b/eng/pipelines/pr-tryit.yml index 4ac394283c..707e59a046 100644 --- a/eng/pipelines/pr-tryit.yml +++ b/eng/pipelines/pr-tryit.yml @@ -20,33 +20,33 @@ jobs: - template: ./templates/install.yml - - template: ./templates/build.yml + # - template: ./templates/build.yml - - task: AzureCLI@1 - displayName: "Publish playground to PR endpoint" - inputs: - azureSubscription: "Azure SDK Engineering System" - scriptLocation: inlineScript - inlineScript: | - az storage blob upload-batch \ - --destination \$web \ - --account-name "cadlplayground" \ - --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ - --source "./packages/playground-website/dist/" \ - --overwrite + # - task: AzureCLI@1 + # displayName: "Publish playground to PR endpoint" + # inputs: + # azureSubscription: "Azure SDK Engineering System" + # scriptLocation: inlineScript + # inlineScript: | + # az storage blob upload-batch \ + # --destination \$web \ + # --account-name "cadlplayground" \ + # --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ + # --source "./packages/playground-website/dist/" \ + # --overwrite - - task: AzureCLI@1 - displayName: "Publish website to PR endpoint" - inputs: - azureSubscription: "Azure SDK Engineering System" - scriptLocation: inlineScript - inlineScript: | - az storage blob upload-batch \ - --destination \$web \ - --account-name "tspwebsitepr" \ - --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ - --source "./packages/website/build/" \ - --overwrite + # - task: AzureCLI@1 + # displayName: "Publish website to PR endpoint" + # inputs: + # azureSubscription: "Azure SDK Engineering System" + # scriptLocation: inlineScript + # inlineScript: | + # az storage blob upload-batch \ + # --destination \$web \ + # --account-name "tspwebsitepr" \ + # --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ + # --source "./packages/website/build/" \ + # --overwrite - script: node eng/scripts/create-tryit-comment.js "cadl-azure" displayName: Check already commented diff --git a/eng/scripts/create-tryit-comment.js b/eng/scripts/create-tryit-comment.js index d41df72ad1..d9be7631c4 100644 --- a/eng/scripts/create-tryit-comment.js +++ b/eng/scripts/create-tryit-comment.js @@ -26,10 +26,11 @@ async function main() { const folderName = process.argv.length > 2 ? `/${process.argv[2]}` : ""; const repo = process.env["BUILD_REPOSITORY_ID"]; const prNumber = process.env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"]; - const ghAuth = process.env.GH_TOKEN; - if (ghAuth === undefined) { + const ghToken = process.env.GH_TOKEN; + if (ghToken === undefined) { throw new Error("GH_TOKEN environment variable is not set"); } + const ghAuth = `Bearer ${ghToken}`; console.log("Looking for comments in", { repo, prNumber }); const data = await listComments(repo, prNumber, ghAuth); From e65969a6a964499171c8eb4be08756135603a15a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 12 Dec 2023 10:32:02 -0800 Subject: [PATCH 3/3] cleanup --- .github/workflows/tryit-comment.yml | 36 --------------------- eng/pipelines/pr-tryit.yml | 50 ++++++++++++++--------------- 2 files changed, 25 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/tryit-comment.yml diff --git a/.github/workflows/tryit-comment.yml b/.github/workflows/tryit-comment.yml deleted file mode 100644 index e75184be02..0000000000 --- a/.github/workflows/tryit-comment.yml +++ /dev/null @@ -1,36 +0,0 @@ -# IMPORTANT: DO NOT CHECKOUT -name: Make try it comment - -on: - pull_request_target: - types: [opened, reopened] - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - pull-requests: write - -jobs: - # Create PR - pr_created: - name: Provide try it comments - runs-on: ubuntu-latest - steps: - - uses: actions/github-script@v5 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const prNumber = ${{ github.event.pull_request.number }}; - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: [ - `Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):`, - `Playground: https://cadlplayground.z22.web.core.windows.net/prs/${prNumber}/`, - "", - `Website: https://tspwebsitepr.z22.web.core.windows.net/prs/${prNumber}/`, - - ].join("\n") - }) diff --git a/eng/pipelines/pr-tryit.yml b/eng/pipelines/pr-tryit.yml index 707e59a046..4ac394283c 100644 --- a/eng/pipelines/pr-tryit.yml +++ b/eng/pipelines/pr-tryit.yml @@ -20,33 +20,33 @@ jobs: - template: ./templates/install.yml - # - template: ./templates/build.yml + - template: ./templates/build.yml - # - task: AzureCLI@1 - # displayName: "Publish playground to PR endpoint" - # inputs: - # azureSubscription: "Azure SDK Engineering System" - # scriptLocation: inlineScript - # inlineScript: | - # az storage blob upload-batch \ - # --destination \$web \ - # --account-name "cadlplayground" \ - # --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ - # --source "./packages/playground-website/dist/" \ - # --overwrite + - task: AzureCLI@1 + displayName: "Publish playground to PR endpoint" + inputs: + azureSubscription: "Azure SDK Engineering System" + scriptLocation: inlineScript + inlineScript: | + az storage blob upload-batch \ + --destination \$web \ + --account-name "cadlplayground" \ + --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ + --source "./packages/playground-website/dist/" \ + --overwrite - # - task: AzureCLI@1 - # displayName: "Publish website to PR endpoint" - # inputs: - # azureSubscription: "Azure SDK Engineering System" - # scriptLocation: inlineScript - # inlineScript: | - # az storage blob upload-batch \ - # --destination \$web \ - # --account-name "tspwebsitepr" \ - # --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ - # --source "./packages/website/build/" \ - # --overwrite + - task: AzureCLI@1 + displayName: "Publish website to PR endpoint" + inputs: + azureSubscription: "Azure SDK Engineering System" + scriptLocation: inlineScript + inlineScript: | + az storage blob upload-batch \ + --destination \$web \ + --account-name "tspwebsitepr" \ + --destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \ + --source "./packages/website/build/" \ + --overwrite - script: node eng/scripts/create-tryit-comment.js "cadl-azure" displayName: Check already commented