|
8 | 8 | pull_request: |
9 | 9 | paths-ignore: |
10 | 10 | - '**.md' |
| 11 | + repository_dispatch: |
| 12 | + types: [ ok-to-test-command ] |
11 | 13 |
|
12 | 14 | jobs: |
13 | 15 |
|
14 | | - validate: |
| 16 | + integration-test-trusted: |
| 17 | + # actions that are trusted by default must only be opened from within the repo, and skipped for forks because they'll fail there |
| 18 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository |
15 | 19 | strategy: |
16 | 20 | matrix: |
17 | 21 | os: [ubuntu-latest, windows-latest, macos-latest] |
|
49 | 53 | pip install ruff |
50 | 54 | ruff check --output-format=github --exclude=src/onepassword/lib/,example/ . |
51 | 55 | continue-on-error: true |
| 56 | + |
| 57 | + # This action is called by the /ok-to-test command, once the forked PR's code has been security reviewed. |
| 58 | + # It will checkout the forked (and now trusted) code and it will run the integration tests on it. |
| 59 | + # If the tests are successful this action will proceed to update the status of the forked PR integration check. |
| 60 | + integration-test-fork: |
| 61 | + # required permissions for updating the status of the pull request checks |
| 62 | + permissions: |
| 63 | + pull-requests: write |
| 64 | + checks: write |
| 65 | + strategy: |
| 66 | + matrix: |
| 67 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 68 | + runs-on: ${{ matrix.os }} |
| 69 | + if: | |
| 70 | + github.event_name == 'repository_dispatch' && |
| 71 | + github.event.client_payload.slash_command.args.named.sha != '' && |
| 72 | + contains( |
| 73 | + github.event.client_payload.pull_request.head.sha, |
| 74 | + github.event.client_payload.slash_command.args.named.sha |
| 75 | + ) |
| 76 | + steps: |
| 77 | + |
| 78 | + # Check out merge commit |
| 79 | + - name: Fork based /ok-to-test checkout |
| 80 | + uses: actions/checkout@v4 |
| 81 | + with: |
| 82 | + ref: ${{ github.event.client_payload.pull_request.head.sha }} |
| 83 | + |
| 84 | + - name: Set up Python |
| 85 | + uses: actions/setup-python@v4 |
| 86 | + with: |
| 87 | + python-version: '3.x' |
| 88 | + |
| 89 | + - name: Integration Test |
| 90 | + env: |
| 91 | + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.TEST_SERVICE_ACCOUNT_TOKEN }} |
| 92 | + run: | |
| 93 | + pip install pytest && |
| 94 | + pip install pytest-asyncio && |
| 95 | + pip install pydantic && |
| 96 | + python -m pytest src/onepassword/test_client.py |
| 97 | +
|
| 98 | + - run: | |
| 99 | + echo "Integration tests completed successfully!" |
| 100 | +
|
| 101 | + # Update check run called "integration-fork" on the forked PR |
| 102 | + - uses: actions/github-script@v6 |
| 103 | + id: update-check-run |
| 104 | + if: ${{ always() }} |
| 105 | + env: |
| 106 | + job: ${{ github.job }} |
| 107 | + ref: ${{ github.event.client_payload.pull_request.head.sha }} |
| 108 | + # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run |
| 109 | + conclusion: ${{ job.status }} |
| 110 | + with: |
| 111 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + script: | |
| 113 | + const { data: checks } = await github.rest.checks.listForRef({ |
| 114 | + ...context.repo, |
| 115 | + process.env.ref |
| 116 | + }); |
| 117 | +
|
| 118 | + const check = checks.check_runs.filter(c => c.name === process.env.job); |
| 119 | +
|
| 120 | + const { data: result } = await github.rest.checks.update({ |
| 121 | + ...context.repo, |
| 122 | + check_run_id: check[0].id, |
| 123 | + status: 'completed', |
| 124 | + conclusion: process.env.conclusion |
| 125 | + }); |
| 126 | +
|
| 127 | + return result; |
0 commit comments