chore: Trigger ok-to-test using commit message #5928
This file contains 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 Automation test suite | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
on: | |
pull_request: | |
branches: | |
- release | |
- master | |
- pg | |
types: [ labeled, synchronize ] | |
jobs: | |
checkTestLabelAndCommit: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
outputs: | |
ok_to_test: ${{ steps.checkLabel.outputs.ok_to_test }} | |
commit_contains_test: ${{ steps.checkCommitMessage.outputs.commit_contains_test }} | |
steps: | |
- name: Check PR Label | |
id: checkLabel | |
uses: actions/github-script@v7 | |
with: | |
# This script will check if the PR has ok-to-test label. | |
# To avoid being dependent on the event which triggered this workflow, | |
# we will always get the pull request labels directly from the context | |
# It will later set the output to be "true" or "false". | |
script: | | |
const labels = context.payload.pull_request.labels.map(label => label.name); | |
if (labels.includes("ok-to-test")) { | |
console.log("Label 'ok-to-test' is present"); | |
core.setOutput("ok_to_test", "true"); | |
} else { | |
console.log("Label 'ok-to-test' is not present"); | |
core.setOutput("ok_to_test", "false"); | |
} | |
# Checkout the code in the current branch in case the workflow is called because of a branch push event | |
- name: Checkout the head commit of the branch | |
uses: actions/checkout@v4 | |
with: | |
repository: appsmithorg/appsmith | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Check Commit Message | |
id: checkCommitMessage | |
run: | | |
commit_message=$(git log -1 --pretty=%B) | |
# Print the commit message for debugging | |
echo "Commit Message: $commit_message" | |
if [[ "$commit_message" == *"/ok-to-test tags="* ]]; then | |
echo "Commit message contains '/ok-to-test tags='" | |
echo "commit_contains_test=true" >> $GITHUB_OUTPUT | |
echo "commit_contains_test: $commit_contains_test" | |
else | |
echo "Commit message does not contain '/ok-to-test tags='" | |
echo "commit_contains_test=false" >> $GITHUB_OUTPUT | |
echo "commit_contains_test: $commit_contains_test" | |
fi | |
mark-stale: | |
needs: [ checkTestLabelAndCommit ] | |
if: needs.checkTestLabelAndCommit.outputs.ok_to_test == 'false' && needs.checkTestLabelAndCommit.outputs.commit_contains_test == 'false' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# In case of a no label present, mark the Cypress status to be stale | |
- name: Mark the Cypress response to be stale | |
uses: actions/github-script@v7 | |
env: | |
NODE_PATH: "${{ github.workspace }}/.github/workflows/scripts" | |
BODY: | | |
Tests have not run on the HEAD ${{ github.event.pull_request.head.sha }} yet | |
with: | |
script: | | |
require("write-cypress-status.js")({core, context, github}, "warning", process.env.BODY) | |
parse-tags-from-commit-message: | |
needs: [ checkTestLabelAndCommit ] | |
if: needs.checkTestLabelAndCommit.outputs.commit_contains_test == 'true' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
outputs: | |
tags: ${{ steps.parseTagsFromCommit.outputs.tags }} | |
spec: ${{ steps.parseTagsFromCommit.outputs.spec }} | |
matrix: ${{ steps.checkAll.outputs.matrix }} | |
steps: | |
# Checkout the code in the current branch in case the workflow is called because of a branch push event | |
- name: Checkout the head commit of the branch | |
uses: actions/checkout@v4 | |
with: | |
repository: appsmithorg/appsmith | |
- name: Parse tags from commit message | |
id: parseTagsFromCommit | |
run: | | |
commit_message=$(git log -1 --pretty=%B) | |
# Regex to match '/ok-to-test tags=' followed by any text within optional quotes | |
if [[ "$commit_message" =~ /ok-to-test[[:space:]]+tags=[[:space:]]*["'']?([^"'\n]*)["'']? ]]; then | |
tags=${BASH_REMATCH[1]} | |
echo "Commit contains /ok-to-test tags= with tags: $tags" | |
echo "has_test_spec=true" >> $GITHUB_OUTPUT | |
echo "tags_from_commit=$tags" >> $GITHUB_OUTPUT | |
else | |
echo "No /ok-to-test tags= found in the commit message" | |
echo "has_test_spec=false" >> $GITHUB_OUTPUT | |
echo "tags_from_commit=" >> $GITHUB_OUTPUT | |
fi | |
# In case of a run with all test cases, allocate a larger matrix | |
- name: Check if @tag.All is present in tags | |
id: checkAll | |
run: | | |
if [[ -n "${{ steps.parseTagsFromCommit.outputs.spec }}" ]]; then | |
echo "matrix=[0]" >> $GITHUB_OUTPUT | |
else | |
tags="${{ steps.parseTagsFromCommit.outputs.tags }}" | |
if [[ $tags == "@tag.All" ]]; then | |
echo "matrix=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]" >> $GITHUB_OUTPUT | |
else | |
echo "matrix=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 | |
perform-test-for-tags-in-commit-message: | |
needs: [ parse-tags-from-commit-message ] | |
if: success() | |
uses: ./.github/workflows/pr-cypress.yml | |
secrets: inherit | |
with: | |
tags: ${{ needs.parse-tags-from-commit-message.outputs.tags}} | |
spec: ${{ needs.parse-tags-from-commit-message.outputs.spec}} | |
matrix: ${{ needs.parse-tags-from-commit-message.outputs.matrix}} | |
is-pg-build: ${{ github.event.pull_request.base.ref == 'pg' }} | |
parse-tags-from-pr-description: | |
needs: [ checkTestLabelAndCommit ] | |
if: needs.checkTestLabelAndCommit.outputs.ok_to_test == 'true' && needs.checkTestLabelAndCommit.outputs.commit_contains_test == 'false' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
defaults: | |
run: | |
shell: bash | |
outputs: | |
tags: ${{ steps.parseTags.outputs.tags }} | |
spec: ${{ steps.parseTags.outputs.spec }} | |
matrix: ${{ steps.checkAll.outputs.matrix }} | |
steps: | |
# Checkout the code in the current branch in case the workflow is called because of a branch push event | |
- name: Checkout the head commit of the branch | |
uses: actions/checkout@v4 | |
with: | |
repository: appsmithorg/appsmith | |
# Reads the PR description to retrieve the /ok-to-test or, if that's absent, the /test command | |
- name: Read tags from PR description | |
uses: actions/github-script@v7 | |
id: parseTags | |
env: | |
NODE_PATH: "${{ github.workspace }}/.github/workflows/scripts" | |
with: | |
script: | | |
require("test-tag-parser.js")({core, context, github}) | |
# In case of a run with all test cases, allocate a larger matrix | |
- name: Check if @tag.All is present in tags | |
id: checkAll | |
run: | | |
if [[ -n "${{ steps.parseTags.outputs.spec }}" ]]; then | |
echo "matrix=[0]" >> $GITHUB_OUTPUT | |
else | |
tags="${{ steps.parseTags.outputs.tags }}" | |
if [[ $tags == "@tag.All" ]]; then | |
echo "matrix=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]" >> $GITHUB_OUTPUT | |
else | |
echo "matrix=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" >> $GITHUB_OUTPUT | |
fi | |
fi | |
# In case of a runnable command, update the PR with run details | |
- name: Add test response with link to workflow run | |
uses: actions/github-script@v7 | |
env: | |
NODE_PATH: "${{ github.workspace }}/.github/workflows/scripts" | |
BODY: | | |
Your tests are running. | |
Tests running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}> | |
Commit: ${{ github.event.pull_request.head.sha }} | |
Workflow: `${{ github.workflow }}` | |
Tags: `${{ steps.parseTags.outputs.tags }}` | |
Spec: `${{ steps.parseTags.outputs.spec }}` | |
with: | |
script: | | |
require("write-cypress-status.js")({core, context, github}, "important", process.env.BODY) | |
# Call the workflow to run Cypress tests | |
perform-test-for-tags-in-pr-description: | |
needs: [ parse-tags-from-pr-description ] | |
if: success() | |
uses: ./.github/workflows/pr-cypress.yml | |
secrets: inherit | |
with: | |
tags: ${{ needs.parse-tags-from-pr-description.outputs.tags}} | |
spec: ${{ needs.parse-tags-from-pr-description.outputs.spec}} | |
matrix: ${{ needs.parse-tags-from-pr-description.outputs.matrix}} | |
is-pg-build: ${{ github.event.pull_request.base.ref == 'pg' }} | |