dpgaspar commented on code in PR #31340:
URL: https://github.com/apache/superset/pull/31340#discussion_r1933772022


##########
.github/workflows/ephemeral-env.yml:
##########
@@ -1,145 +1,152 @@
 name: Ephemeral env workflow
 
-# Example manual trigger:  gh workflow run ephemeral-env.yml --ref 
fix_ephemerals  --field comment_body="/testenv up" --field issue_number=666
+# Example manual trigger:
+# gh workflow run ephemeral-env.yml --ref fix_ephemerals --field 
label_name="testenv-up" --field issue_number=666
 
 on:
-  issue_comment:
-    types: [created]
+  pull_request:
+    types:
+      - labeled
   workflow_dispatch:
     inputs:
-      comment_body:
-        description: 'Comment body to simulate /testenv command'
+      label_name:
+        description: 'Label name to simulate label-based /testenv trigger'
         required: true
-        default: '/testenv up'
+        default: 'testenv-up'
       issue_number:
         description: 'Issue or PR number'
         required: true
 
 jobs:
-  ephemeral-env-comment:
+  ephemeral-env-label:
     concurrency:
-      group: ${{ github.workflow }}-${{ github.event.inputs.issue_number || 
github.event.issue.number || github.run_id }}-comment
+      group: ${{ github.workflow }}-${{ github.event.pull_request.number || 
github.run_id }}-label
       cancel-in-progress: true
-    name: Evaluate ephemeral env comment trigger (/testenv)
+    name: Evaluate ephemeral env label trigger
     runs-on: ubuntu-24.04
     permissions:
       pull-requests: write
     outputs:
-      slash-command: ${{ steps.eval-body.outputs.result }}
+      slash-command: ${{ steps.eval-label.outputs.result }}
       feature-flags: ${{ steps.eval-feature-flags.outputs.result }}
+      sha: ${{ steps.get-sha.outputs.sha }}
     env:
       DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
       DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
 
     steps:
-    - name: Debug
-      run: |
-        echo "Comment on PR #${{ github.event.issue.number }} by ${{ 
github.event.issue.user.login }}, ${{ github.event.comment.author_association 
}}"
-
-    - name: Eval comment body for /testenv slash command
-      uses: actions/github-script@v7
-      env:
-        COMMENT_BODY: ${{ github.event.inputs.comment_body || 
github.event.comment.body }}
-      id: eval-body
-      with:
-        result-encoding: string
-        script: |
-          const pattern = /^\/testenv (up|down)/;
-          const result = pattern.exec(process.env.COMMENT_BODY || '');
-          return result === null ? 'noop' : result[1];
-
-    - name: Looking for feature flags
-      uses: actions/github-script@v7
-      env:
-        COMMENT_BODY: ${{ github.event.inputs.comment_body || 
github.event.comment.body }}
-      id: eval-feature-flags
-      with:
-        script: |
-          const pattern = /FEATURE_(\w+)=(\w+)/g;
-          let results = [];
-          [...process.env.COMMENT_BODY.matchAll(pattern)].forEach(match => {
-            const config = {
-              name: `SUPERSET_FEATURE_${match[1]}`,
-              value: match[2],
-            };
-            results.push(config);
-          });
-          return results;
-
-    - name: Limit to committers
-      if: >
-        steps.eval-body.outputs.result != 'noop' &&
-        github.event_name == 'issue_comment' &&
-        github.event.comment.author_association != 'MEMBER' &&
-        github.event.comment.author_association != 'OWNER'
-      uses: actions/github-script@v7
-      with:
-        github-token: ${{ github.token }}
-        script: |
-          const errMsg = '@${{ github.event.comment.user.login }} Ephemeral 
environment creation is currently limited to committers.';
-          github.rest.issues.createComment({
-            issue_number: ${{ github.event.issue.number }},
-            owner: context.repo.owner,
-            repo: context.repo.repo,
-            body: errMsg
-          });
-          core.setFailed(errMsg);
-
-    - name: Reply with confirmation comment
-      uses: actions/github-script@v7
-      with:
-        github-token: ${{ secrets.GITHUB_TOKEN }}
-        script: |
-          const issueNumber = ${{ github.event.inputs.issue_number || 
github.event.issue.number }};
-          const user = '${{ github.event.comment.user.login || github.actor 
}}';
-          const action = '${{ steps.eval-body.outputs.result }}';
-          const runId = context.runId;
-          const workflowUrl = 
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
-          const body = `@${user} Processing your ephemeral environment request 
[here](${workflowUrl}).`;
-          if (action !== 'noop') {
+      - name: Check for the "testenv-up" label
+        id: eval-label
+        run: |
+          if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
+            LABEL_NAME="${{ github.event.inputs.label_name }}"
+          else
+            LABEL_NAME="${{ github.event.label.name }}"
+          fi
+
+          echo "Evaluating label: $LABEL_NAME"
+
+          if [[ "$LABEL_NAME" == "testenv-up" ]]; then
+            echo "result=up" >> $GITHUB_OUTPUT
+          else
+            echo "result=noop" >> $GITHUB_OUTPUT
+            exit 1
+          fi
+
+      - name: Get PR Info
+        uses: actions/github-script@v7
+        id: get-pr-info
+        with:
+          script: |
+            const pull_number = context.payload.pull_request
+              ? context.payload.pull_request.number
+              : context.payload.inputs.issue_number;
+
+            if (!pull_number) {
+              throw new Error("Pull request number is not available.");
+            }
+
+            const pr = await github.rest.pulls.get({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              pull_number,
+            });
+
+            return pr.data;
+
+      - name: Check if a commit was pushed after PR was labeled
+        id: get-sha
+        env:
+          COMMENT_AT: ${{ github.event.pull_request.updated_at }}
+          PUSHED_AT: ${{ fromJSON(steps.get-pr-info.outputs.result).pushed_at 
}}
+        run: |
+          if [[ $(date -d "$PUSHED_AT" +%s) -gt $(date -d "$COMMENT_AT" +%s) 
]]; then
+           echo "Commit was pushed after the PR was updated."
+           exit 1
+          fi
+          echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha 
}}" >> $GITHUB_OUTPUT

Review Comment:
   Ok removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to