Ianjennings/testdriver test #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Test with TestDriver | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| actions: read | |
| pull-requests: write | |
| jobs: | |
| test-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install global dependencies | |
| run: | | |
| npm install -g typescript prettier eslint vsce | |
| - name: Install project dependencies | |
| run: npm install | |
| - name: Build .vsix package | |
| run: | | |
| npm run package | |
| npx vsce package | |
| - name: Set .vsix file path | |
| id: get_vsix | |
| run: | | |
| VERSION=$(jq -r '.version' package.json) | |
| VSIX_PATH="./testdriver-${VERSION}.vsix" | |
| if [ ! -f "$VSIX_PATH" ]; then | |
| echo "VSIX file not found at $VSIX_PATH" | |
| exit 1 | |
| fi | |
| echo "vsix_path=$VSIX_PATH" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Upload .vsix as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: testdriver-extension-pr-${{ github.event.number || 'manual' }} | |
| path: ${{ steps.get_vsix.outputs.vsix_path }} | |
| retention-days: 30 | |
| - name: Set artifact info for TestDriver | |
| id: set_artifact_info | |
| run: | | |
| ARTIFACT_NAME="testdriver-extension-pr-${{ github.event.number || 'manual' }}" | |
| echo "artifact_name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT | |
| echo "run_id=${{ github.run_id }}" >> $GITHUB_OUTPUT | |
| echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT | |
| - name: Install TestDriver CLI | |
| run: npm install -g testdriverai@latest | |
| - name: Run TestDriver tests | |
| env: | |
| TD_GITHUB_REPO: ${{ steps.set_artifact_info.outputs.repo }} | |
| TD_GITHUB_RUN_ID: ${{ steps.set_artifact_info.outputs.run_id }} | |
| TD_ARTIFACT_NAME: ${{ steps.set_artifact_info.outputs.artifact_name }} | |
| TD_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }} | |
| run: | | |
| echo "Running TestDriver with GitHub artifact info:" | |
| echo " Repository: $TD_GITHUB_REPO" | |
| echo " Run ID: $TD_GITHUB_RUN_ID" | |
| echo " Artifact Name: $TD_ARTIFACT_NAME" | |
| npx testdriverai@latest run testdriver/onboarding.yaml | |
| - name: Comment on PR with results | |
| if: always() && github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const success = '${{ job.status }}' === 'success'; | |
| const runUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`; | |
| const artifactName = '${{ steps.set_artifact_info.outputs.artifact_name }}'; | |
| const body = success | |
| ? `✅ **TestDriver tests passed!** | |
| The VS Code extension was successfully built and tested. | |
| 📦 **Artifact:** ${artifactName} | |
| 🔗 **Test Run:** [View full results](${runUrl})` | |
| : `❌ **TestDriver tests failed** | |
| The VS Code extension build or tests encountered an error. | |
| 📦 **Artifact:** ${artifactName} | |
| 🔗 **Test Run:** [View full results](${runUrl}) | |
| Please check the logs for more details.`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); |