Skip to content

Commit

Permalink
[CHORE] Make Update JavaScript action run in PR context (hedyorg#3689)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr authored Nov 22, 2022
1 parent 74c7a76 commit b403244
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/update-javascript-on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Automatically update JavaScript bundle
on:
push:
branches: [ main ]
pull_request_target:
pull_request:
branches: [ main ]

jobs:
Expand All @@ -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
Expand All @@ -38,9 +40,10 @@ jobs:

- name: Commit changed files
uses: stefanzweifel/[email protected]
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 }}
4 changes: 1 addition & 3 deletions static/js/logs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


export const logs = {

initialize: function() {
Expand Down Expand Up @@ -114,4 +112,4 @@ export const logs = {
function updateCopyButtonText(copyBtn: any, text: string) {
copyBtn.text(text);
setTimeout(function() {copyBtn.html("⇥")}, 2000);
}
}
2 changes: 1 addition & 1 deletion static/js/markers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ export class Markers {
interface MarkerLocation {
readonly line: number;
readonly id: number;
}
}

0 comments on commit b403244

Please sign in to comment.