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


##########
.github/workflows/ephemeral-env.yml:
##########
@@ -1,145 +1,121 @@
 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: Check for the "testenv-up" label
+        id: eval-label
+        run: |
+          if [[ "${{ github.event.label.name }}" == "testenv-up" ]]; then
+            echo "result=up" >> $GITHUB_OUTPUT
+          else
+            echo "result=noop" >> $GITHUB_OUTPUT
+            exit 1
+          fi
 
-    - 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: Get PR Info
+        uses: actions/github-script@v7
+        id: get-pr-info
+        with:
+          script: |
+            const pr = await github.rest.pulls.get({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              pull_number: context.payload.pull_request.number,
+            });
+            return pr.data;
 
-    - 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: 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:
   concurrency seems fine to me (pushed a fix). it's unique at the PR level, so 
label events for new commits will cancel previous runs.
   
   +1 on using supersetbot ephemeral deploy



-- 
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