PromucFlow_constructor/.github/workflows/pr-automation.yml
Shrikant Sharat Kandula 4a6dc86a60
ci: Update PR description with GitHub Script (#34292)
This PR switches the steps updating PR description to a local Javascript
script, run using `actions/github-script`, instead of depending on an
external third-party action.

Why? Besides reducing our dependency on third-party actions, which have
been found to break with surprises, we need this to fix a bug with the
`/test` command. The `/test` command, when is written with invalid tags,
reports the error in the workflow run, but doesn't update the PR
description. Because of how it's written in Javascript, we need a
Javascript way to update the description to fix that. This will provide
for that.

Further PRs will replace other uses of PR description update steps with
this.

**/test sanity**



<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9556890596>
> Commit: 00d06858f6f7d14c6393cb16c894ddfd808b7cf8
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9556890596&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`

<!-- end of auto-generated comment: Cypress test results  -->



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

## Summary by CodeRabbit

- **Chores**
- Updated GitHub Actions workflow to enhance pull request automation
with Cypress test results.
  - Improved PR body updates with detailed test outcomes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-18 09:39:50 +05:30

198 lines
8.9 KiB
YAML

name: PR Automation test suite
on:
pull_request:
branches: [release]
types:
- opened
- labeled
jobs:
parse-tags:
runs-on: ubuntu-latest
permissions:
pull-requests: write
defaults:
run:
shell: bash
outputs:
tags: ${{ steps.checkAll.outputs.tags }}
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
# Checks for ok-to-test label presence in PR
- name: Check label
run: |
if [[ '${{ github.event.label.name }}' != 'ok-to-test' ]]; then
echo "Irrelevant label '${{ github.event.label.name }}' added! "
exit 1
fi
# Reads the PR description to retrieve the /ok-to-test or, if that's absent, the /test command
- name: Get tags
uses: actions/github-script@v7
id: getTags
env:
NODE_PATH: "${{ github.workspace }}/.github/workflows/scripts"
with:
script: |
const testTagParser = require("test-tag-parser.js")
core.setOutput("tags", testTagParser.parseTags({core, context}))
# Parses the retrieved /ok-to-test slash command to retrieve tags
- name: Parse tags
id: parseTags
run: |
if [[ '${{ steps.getTags.outputs.tags }}' != '' ]]; then
echo "tags=${{ steps.getTags.outputs.tags }}" >> $GITHUB_OUTPUT
echo "outcome=success" >> $GITHUB_OUTPUT
else
echo "Tags were not found!"
echo "outcome=failure" >> $GITHUB_OUTPUT
fi
# In case of missing tags, guides towards correct usage in test response
- name: Add test response with tags documentation link
if: steps.parseTags.outputs.outcome != 'success'
uses: nefrob/pr-description@v1.1.2
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> The provided command lacks proper tags. Please modify PR body, specifying the tags you want to include or use `/ok-to-test tags="@tag.All"` to run all specs.
> Explore the tags documentation [here](https://www.notion.so/appsmith/Ok-to-test-With-Tags-7c0fc64d4efb4afebf53348cd6252918)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of missing tags, exit the workflow with failure
- name: Stop the workflow run if tags are not present
if: steps.parseTags.outputs.outcome != 'success'
run: exit 1
- name: Check Tags
env:
TAG_LIST: ${{ steps.getTags.outputs.tags }}
id: checkTags
run: |
export IFS=","
for tag in ${TAG_LIST//[[:blank:]]/}; do
if [[ `cat app/client/cypress/tags.js|grep -w $tag|wc -l` != 1 && $tag != "@tag.All" ]]; then
echo "Incorrect Tags"
echo "outcome=failure" >> $GITHUB_OUTPUT
fi
done
shell: bash
# In case of incorrect tags, guides towards correct tags
- name: Add test response with tags list link
if: steps.checkTags.outputs.outcome == 'failure'
uses: nefrob/pr-description@v1.1.2
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> The provided command contains incorrect tags. Please modify PR body, specifying the tags you want to include or use `/ok-to-test tags="@tag.All"` to run all specs.
> Please find complete list of tags [here](https://github.com/appsmithorg/appsmith/blob/release/app/client/cypress/tags.js)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of incorrect tags, exit the workflow with failure
- name: Stop the workflow run if tags are incorrect
if: steps.checkTags.outputs.outcome == 'failure'
run: exit 1
# 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: |
tags="${{ steps.parseTags.outputs.tags }}"
if [[ ($tags == *"ALL"* || $tags == *"All"* || $tags == *"all"*) && $tags != *"@tag.All"* ]]; then
echo "invalid_tags_all=$tags" >> $GITHUB_OUTPUT
elif [[ $tags == *"@tag.All"* ]]; then
echo "tags=" >> $GITHUB_OUTPUT
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 "tags=$tags" >> $GITHUB_OUTPUT
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
# In case of incorrect usage for all test cases, inform the PR author of correct usage
- name: Add test response to use correct @tag.All format
if: steps.checkAll.outputs.invalid_tags_all != ''
uses: nefrob/pr-description@v1.1.2
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> Please use `/ok-to-test tags="@tag.All"` to run all specs.
> Explore the tags documentation [here](https://www.notion.so/appsmith/Ok-to-test-With-Tags-7c0fc64d4efb4afebf53348cd6252918)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of incorrect usage for all test cases, exit the workflow with failure
- name: Stop the workflow run if given @tag.All format is wrong
if: steps.checkAll.outputs.invalid_tags_all != ''
run: exit 1
# In case of a run with all test cases, inform the PR author of better usage
- name: Add test response to use @tag.All
if: steps.checkAll.outputs.tags == ''
uses: nefrob/pr-description@v1.1.2
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> Whoa, @tag.All spotted in your test suite! 🚀
> While @tag.All is cool, like a catch-all net, why not try specific tags? 🏷️
> Narrow down your suite with specific tags for quicker and more accurate tests! 🚀 Less waiting, more zipping through tests like a ninja!
> Explore the tags documentation [here](https://www.notion.so/appsmith/Ok-to-test-With-Tags-7c0fc64d4efb4afebf53348cd6252918)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# 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: |
> [!IMPORTANT]
> 🟣 🟣 🟣 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.checkAll.outputs.tags }}`
with:
script: |
require("write-cypress-comment.js")({core, context, github}, process.env.BODY)
# Call the workflow to run Cypress tests
perform-test:
needs: [parse-tags]
if: success()
uses: ./.github/workflows/pr-cypress.yml
secrets: inherit
with:
tags: ${{ needs.parse-tags.outputs.tags}}
matrix: ${{ needs.parse-tags.outputs.matrix}}
is-pg-build: ${{ github.event.pull_request.base.ref == 'pg' }}