Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass secrets to approved workflow jobs #258

Merged
merged 10 commits into from
Dec 2, 2023
6 changes: 6 additions & 0 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ When testing locally, ensure at least linting and unit tests pass by running `np
Additionally, sending a PR is highly recommended with every change as there are several GitHub
Actions jobs that execute what are effectively integration tests for this GitHub Action.

#### Checks on PRs

Actions that run the integration tests on PRs from a fork will require approval before running.
These checks use stored secrets so the changes should be reviewed before approving the workflow to
avoid accidently leaking tokens!

### Releasing

* Check the status of this project's GitHub Milestone to be released for issues that should be shipped with the release.
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Tests
on:
pull_request:
pull_request_target:
types: [opened, synchronize]
push:
branches:
- main
Expand All @@ -13,10 +14,22 @@ jobs:
- run: npm ci && npm run build
- run: npm test

access_check:
runs-on: ubuntu-latest
steps:
- name: Check user permissions
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.author_association != 'MEMBER' }}
Copy link
Member Author

Choose a reason for hiding this comment

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

The pull_request_target still uses the event.pull_request values from what I can tell: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target

run: |
echo "Action was not triggered by an organization member. Exiting now."
exit 1

integration_test_botToken:
runs-on: ubuntu-latest
needs: access_check
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- name: Post message to Slack via botToken
id: slackToken
Expand Down Expand Up @@ -47,8 +60,11 @@ jobs:

integration_test_webhook:
runs-on: ubuntu-latest
needs: access_check
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- run: echo "${{ github.event_name }}"
- name: push trigger
Expand Down Expand Up @@ -80,8 +96,11 @@ jobs:

integration_test_incoming_webhook:
runs-on: ubuntu-latest
needs: access_check
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- run: echo "${{ github.event_name }}"
- name: Post message to Slack via incoming webhook
Expand All @@ -100,8 +119,11 @@ jobs:

integration_test_file_payload:
runs-on: ubuntu-latest
needs: access_check
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm ci && npm run build
- name: Dump out GitHub Context
run: echo $JSON
Expand Down