You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/12/27 13:52:20 UTC

[airflow-cancel-workflow-runs] 04/44: Add additional validation

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow-cancel-workflow-runs.git

commit 6595731233df96cc183f56db9db19a4313e7febf
Author: Jason T. Greene <ja...@redhat.com>
AuthorDate: Tue Feb 4 03:26:38 2020 -0600

    Add additional validation
---
 dist/index.js | 16 +++++++++++++---
 src/main.ts   | 18 +++++++++++++++---
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 88b1aee..3995113 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1472,14 +1472,24 @@ function run() {
             const token = core.getInput('token');
             const selfRunId = getRequiredEnv('GITHUB_RUN_ID');
             const repository = getRequiredEnv('GITHUB_REPOSITORY');
+            const eventName = getRequiredEnv('GITHUB_EVENT_NAME');
             const [owner, repo] = repository.split('/');
-            const refsPrefix = 'refs/heads/';
+            const branchPrefix = 'refs/heads/';
+            const tagPrefix = 'refs/tags/';
+            if (eventName !== 'push') {
+                core.info('Skipping non-push event');
+                return;
+            }
             let branch = getRequiredEnv('GITHUB_REF');
-            if (!branch.startsWith(refsPrefix)) {
+            if (!branch.startsWith(branchPrefix)) {
+                if (branch.startsWith(tagPrefix)) {
+                    core.info(`Skipping tag build`);
+                    return;
+                }
                 const message = `${branch} was not an expected branch ref (refs/heads/).`;
                 throw new Error(message);
             }
-            branch = branch.replace(refsPrefix, '');
+            branch = branch.replace(branchPrefix, '');
             core.info(`Branch is ${branch}, repo is ${repo}, and owner is ${owner}, and id is ${selfRunId}`);
             const octokit = new github.GitHub(token);
             const listRuns = octokit.actions.listRepoWorkflowRuns.endpoint.merge({
diff --git a/src/main.ts b/src/main.ts
index 44db6fe..bfe9c55 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -7,15 +7,27 @@ async function run(): Promise<void> {
 
     const selfRunId = getRequiredEnv('GITHUB_RUN_ID')
     const repository = getRequiredEnv('GITHUB_REPOSITORY')
+    const eventName = getRequiredEnv('GITHUB_EVENT_NAME')
+
     const [owner, repo] = repository.split('/')
-    const refsPrefix = 'refs/heads/'
+    const branchPrefix = 'refs/heads/'
+    const tagPrefix = 'refs/tags/'
+
+    if (eventName !== 'push') {
+      core.info('Skipping non-push event')
+      return
+    }
 
     let branch = getRequiredEnv('GITHUB_REF')
-    if (!branch.startsWith(refsPrefix)) {
+    if (!branch.startsWith(branchPrefix)) {
+      if (branch.startsWith(tagPrefix)) {
+        core.info(`Skipping tag build`)
+        return
+      }
       const message = `${branch} was not an expected branch ref (refs/heads/).`
       throw new Error(message)
     }
-    branch = branch.replace(refsPrefix, '')
+    branch = branch.replace(branchPrefix, '')
 
     core.info(
       `Branch is ${branch}, repo is ${repo}, and owner is ${owner}, and id is ${selfRunId}`