1# This GitHub Actions workflow runs JMH benchmarks when a new comment is created on a pull request 2name: Run JMH Benchmarks for Pull Request 3 4on: 5 issue_comment: # This workflow triggers when a comment is created 6 types: [created] 7 8# Only allow one instance of JMH benchmarking to be running at any given time 9concurrency: all 10 11jobs: 12 benchmarking: 13 # Only run this job if a comment on a pull request contains '/benchmark' and is a PR on the uber/NullAway repository 14 if: github.event.issue.pull_request && contains(github.event.comment.body, '/benchmark') && github.repository == 'uber/NullAway' 15 runs-on: ubuntu-latest 16 permissions: write-all 17 18 steps: 19 - name: Add reaction 20 uses: peter-evans/create-or-update-comment@v3 21 with: 22 comment-id: ${{ github.event.comment.id }} 23 reactions: '+1' 24 25 - name: Checkout repository 26 uses: actions/checkout@v3 27 28 - name: Set branch name 29 env: 30 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 run: | 32 chmod +x ./.github/workflows/get_repo_details.sh 33 ./.github/workflows/get_repo_details.sh "${{ secrets.GITHUB_TOKEN }}" "${{ github.event.issue.number }}" "${{ github.repository }}" 34 35 - id: 'auth' 36 name: Authenticating 37 uses: 'google-github-actions/auth@v1' 38 with: 39 credentials_json: '${{ secrets.GCP_SA_KEY_1 }}' 40 41 - name: Set up Google Cloud SDK 42 uses: google-github-actions/setup-gcloud@v1 43 44 - name: Start VM 45 run: gcloud compute instances start nullway-jmh --zone=us-central1-a 46 47 - name: Run benchmarks 48 run: | 49 chmod +x ./.github/workflows/run_gcp_benchmarks.sh 50 ./.github/workflows/run_gcp_benchmarks.sh 51 52 - name: Cleanup 53 # Delete the branch directory on the Google Cloud instance 54 if: always() 55 run: | 56 ./.github/workflows/gcloud_ssh.sh " export BRANCH_NAME=${BRANCH_NAME} && rm -r -f $BRANCH_NAME" 57 58 - name: Formatting Benchmark # Create a text file containing the benchmark results 59 run: | 60 (echo 'Main Branch:'; echo '```' ; cat main_text.txt; echo '```'; echo 'With This PR:'; echo '```' ; cat pr_text.txt; echo '```') > benchmark.txt 61 62 - name: Comment Benchmark 63 uses: mshick/add-pr-comment@v2 64 if: always() # This step is for adding the comment 65 with: 66 message-path: benchmark.txt # The path to the message file to leave as a comment 67 message-id: benchmark 68 - name: Stop VM 69 if: always() 70 run: gcloud compute instances stop nullway-jmh --zone=us-central1-a 71 72 73 74