chore: Ability to run PR automations every time PR updates (#35476)

## Description

By changing the workflow trigger and the way to check for correct
labels, we are trying to allow the PR integrations tests to run every
time the PR is updated. That means, if you push changes, and the PR
already has ok-to-test label, it will rerun the tests based on new
changes



## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10296910575>
> Commit: c59583ba28c8cdff35a12422b8c73838c6efdc85
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10296910575&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Thu, 08 Aug 2024 06:32:48 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new job, `checkTestLabel`, to verify the presence of the
"ok-to-test" label on pull requests.
- Added a new job, `mark-stale`, to mark the Cypress status as stale
when the label is absent.
- **Improvements**
- Updated the `parse-tags` job to run only after the `checkTestLabel`
job, enhancing workflow control.
- Modified the conditions for executing the `parse-tags` job based on
the output of the `checkTestLabel` job.
- **Style**
	- Minor formatting adjustments for job dependencies in the workflow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Hetu Nandu 2024-08-12 11:24:49 +05:30 committed by GitHub
parent 8cbb13ea6e
commit 0afc9dd794
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,17 +1,68 @@
name: PR Automation test suite name: PR Automation test suite
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
on: on:
pull_request: pull_request:
branches: branches:
- release - release
- pg - pg
types: types: [ labeled, synchronize ]
- labeled
jobs: jobs:
parse-tags: checkTestLabel:
runs-on: ubuntu-latest
outputs:
ok_to_test: ${{ steps.checkLabel.outputs.ok_to_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");
}
mark-stale:
needs: [ checkTestLabel ]
if: needs.checkTestLabel.outputs.ok_to_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:
needs: [ checkTestLabel ]
if: needs.checkTestLabel.outputs.ok_to_test == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event.label.name == 'ok-to-test'
permissions: permissions:
pull-requests: write pull-requests: write
defaults: defaults:
@ -27,7 +78,7 @@ jobs:
- name: Checkout the head commit of the branch - name: Checkout the head commit of the branch
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: appsmithorg/appsmith repository: appsmithorg/appsmith
# Reads the PR description to retrieve the /ok-to-test or, if that's absent, the /test command # Reads the PR description to retrieve the /ok-to-test or, if that's absent, the /test command
- name: Read tags from PR description - name: Read tags from PR description
@ -72,7 +123,7 @@ jobs:
# Call the workflow to run Cypress tests # Call the workflow to run Cypress tests
perform-test: perform-test:
needs: [parse-tags] needs: [ parse-tags ]
if: success() if: success()
uses: ./.github/workflows/pr-cypress.yml uses: ./.github/workflows/pr-cypress.yml
secrets: inherit secrets: inherit