From b403244c31d3d3bd362cba3818bfef4829867f64 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 22 Nov 2022 18:20:34 +0100 Subject: [PATCH] [CHORE] Make Update JavaScript action run in PR context (#3689) The event `pull_request_target` (as opposed to `pull_request`) makes it run in the context of `main`, instead of the context of the PR itself. This caused it to use files from `main` instead of the PR, incorrectly representing its success or failure. **How to test** On this PR: * We should be able to change a TS file and see the JS be regenerated and committed. After merging: * The same should happen for fork PRs. In case this action is broken for fork PRs, we should just add something like: ``` if: github.event.push ``` To the commit action, and forego committing on PRs altogether (just leave committing on main), but DO run the generator, so that we can see it if it fails. --- .github/workflows/update-javascript-on-main.yml | 9 ++++++--- static/js/logs.ts | 4 +--- static/js/markers.ts | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/update-javascript-on-main.yml b/.github/workflows/update-javascript-on-main.yml index 36c46e43767..ac5f363e883 100644 --- a/.github/workflows/update-javascript-on-main.yml +++ b/.github/workflows/update-javascript-on-main.yml @@ -5,7 +5,7 @@ name: Automatically update JavaScript bundle on: push: branches: [ main ] - pull_request_target: + pull_request: branches: [ main ] jobs: @@ -14,12 +14,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 1 # This is necessary to bypass branch protection (which will disallow non-reviewed pushes otherwise) token: ${{ secrets.FELIENNE_GITHUB_ACCESS_TOKEN }} + + # This is necessary to check out the - name: Install Nodejs dependencies run: | npm ci @@ -38,9 +40,10 @@ jobs: - name: Commit changed files uses: stefanzweifel/git-auto-commit-action@v2.3.0 + if: github.event_name == 'push' with: commit_message: Automatically update JavaScript bundle 🤖 beep boop - branch: main + branch: ${{ github.head_ref }} env: # This is necessary to bypass branch protection (which will disallow non-reviewed pushes otherwise) GITHUB_TOKEN: ${{ secrets.FELIENNE_GITHUB_ACCESS_TOKEN }} diff --git a/static/js/logs.ts b/static/js/logs.ts index 1d82ad547dd..fc9cee00bc5 100644 --- a/static/js/logs.ts +++ b/static/js/logs.ts @@ -1,5 +1,3 @@ - - export const logs = { initialize: function() { @@ -114,4 +112,4 @@ export const logs = { function updateCopyButtonText(copyBtn: any, text: string) { copyBtn.text(text); setTimeout(function() {copyBtn.html("⇥")}, 2000); -} \ No newline at end of file +} diff --git a/static/js/markers.ts b/static/js/markers.ts index e506ef4f99a..4e24fe18854 100644 --- a/static/js/markers.ts +++ b/static/js/markers.ts @@ -125,4 +125,4 @@ export class Markers { interface MarkerLocation { readonly line: number; readonly id: number; -} \ No newline at end of file +}