浏览代码

Stop CI Jobs on Forks

Closes gh-9701
Josh Cummings 4 年之前
父节点
当前提交
a493660cdb
共有 2 个文件被更改,包括 24 次插入6 次删除
  1. 16 4
      .github/workflows/continuous-integration-workflow.yml
  2. 8 2
      .github/workflows/pr-build-workflow.yml

+ 16 - 4
.github/workflows/continuous-integration-workflow.yml

@@ -17,25 +17,33 @@ env:
   COMMIT_SHA: ${{ github.sha }}
   ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
   ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
+  RUN_JOBS: ${{ github.repository == 'spring-projects/spring-security' }}
 
 jobs:
-  initiate_error_tracking:
-    name: Initiate job-level error tracking
+  prerequisites:
+    name: Pre-requisites for building
     runs-on: ubuntu-latest
+    outputs:
+      runjobs: ${{ steps.continue.outputs.runjobs }}
     steps:
       - uses: actions/checkout@v2
       - name: Initiate error tracking
         uses: spring-projects/track-build-errors-action@v1
         with:
-          job-name: "initiate-error-tracking"
+          job-name: "prerequisites"
       - name: Export errors file
         uses: actions/upload-artifact@v2
         with:
           name: errors
-          path: job-initiate-error-tracking.txt
+          path: job-prerequisites.txt
+      - id: continue
+        name: Determine if should continue
+        run: echo "::set-output name=runjobs::${RUN_JOBS}"
   build_jdk_11:
     name: Build JDK 11
+    needs: [prerequisites]
     runs-on: ubuntu-latest
+    if: needs.prequisites.outputs.runjobs == 'true'
     steps:
       - uses: actions/checkout@v2
       - name: Set up JDK 11
@@ -66,7 +74,9 @@ jobs:
           path: job-${{ github.job }}.txt
   snapshot_tests:
     name: Test against snapshots
+    needs: [prerequisites]
     runs-on: ubuntu-latest
+    if: needs.prequisites.outputs.runjobs == 'true'
     steps:
       - uses: actions/checkout@v2
       - name: Set up JDK
@@ -92,7 +102,9 @@ jobs:
           path: job-${{ github.job }}.txt
   sonar_analysis:
     name: Static Code Analysis
+    needs: [prerequisites]
     runs-on: ubuntu-latest
+    if: needs.prequisites.outputs.runjobs == 'true'
     env:
       SONAR_URL: ${{ secrets.SONAR_URL }}
       SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

+ 8 - 2
.github/workflows/pr-build-workflow.yml

@@ -2,21 +2,27 @@ name: PR Build
 
 on: pull_request
 
+env:
+  RUN_JOBS: ${{ github.repository == 'spring-projects/spring-security' }}
+
 jobs:
   build:
     name: Build
     runs-on: ubuntu-latest
-    if: github.repository == 'spring-projects/spring-security'
     steps:
-      - uses: actions/checkout@v2
+      - if: env.RUN_JOBS == 'true'
+        uses: actions/checkout@v2
       - name: Set up JDK
+        if: env.RUN_JOBS == 'true'
         uses: actions/setup-java@v1
         with:
           java-version: '11'
       - name: Cache Gradle packages
+        if: env.RUN_JOBS == 'true'
         uses: actions/cache@v2
         with:
           path: ~/.gradle/caches
           key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
       - name: Build with Gradle
+        if: env.RUN_JOBS == 'true'
         run: ./gradlew clean build --continue --scan