From b739526bb58e37d5e580311a93e2c85e12527598 Mon Sep 17 00:00:00 2001 From: Keepers Date: Wed, 14 Sep 2022 16:23:17 -0600 Subject: [PATCH] use dorny version of skipping workflow jobs (#768) ## Description The current action workflow skips cause requried actions to be marked as passing until they fail, not marked as incomplete until either passed, failed, or skipped. This change should provide the latter behavior. ## Type of change - [x] :sunflower: Feature ## Issue(s) * #744 ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- .github/workflows/_filechange_checker.yml | 37 +++++++++++++++++++++++ .github/workflows/ci.yml | 32 +++++++++++++++----- .github/workflows/docgen.yml | 6 +++- .github/workflows/image.yml | 7 ++++- .github/workflows/lint.yml | 28 ++++++++++++++--- 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/_filechange_checker.yml diff --git a/.github/workflows/_filechange_checker.yml b/.github/workflows/_filechange_checker.yml new file mode 100644 index 000000000..105a1b33d --- /dev/null +++ b/.github/workflows/_filechange_checker.yml @@ -0,0 +1,37 @@ +name: Filechange Checker + +on: + workflow_call: + outputs: + fileschanged: + description: "'true' if src/** or .github/workflows/** files have changed in the branch" + value: ${{ jobs.file-change-check.outputs.fileschanged }} + +jobs: + file-change-check: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + fileschanged: ${{ steps.checker.outputs.fileschanged }} + steps: + - uses: actions/checkout@v3 + + # only run CI tests if the src folder or workflow actions have changed + - name: Check for file changes in src/ or .github/workflows/ + uses: dorny/paths-filter@v2 + id: dornycheck + with: + list-files: json + filters: | + src: + - 'src/**' + actions: + - '.github/workflows/**' + - name: Check dorny for changes in specified filepaths + id: checker + if: steps.dornycheck.outputs.src == 'true' || steps.dornycheck.outputs.actions == 'true' + run: | + echo "src or workflow file changes occurred" + echo ::set-output name=fileschanged::true \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dc8d3844..229553d36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,26 +9,38 @@ permissions: # required to retrieve AWS credentials id-token: write contents: read + pull-requests: read + +# cancel currently running jobs if a new version of the branch is pushed +concurrency: + group: ci-linting-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: + precheck: + uses: alcionai/corso/.github/workflows/_filechange_checker.yml@issue-744-alt + Test-Suite: + needs: precheck environment: Testing runs-on: ubuntu-latest defaults: run: working-directory: src steps: - - name: Checkout repository uses: actions/checkout@v3 # Get values for cache paths to be used in later steps - - id: go-cache-paths + - name: Local Cache Setup + if: needs.precheck.outputs.fileschanged == 'true' + id: go-cache-paths run: | echo "::set-output name=go-build::$(go env GOCACHE)" echo "::set-output name=go-mod::$(go env GOMODCACHE)" - name: Golang Setup + if: needs.precheck.outputs.fileschanged == 'true' uses: actions/setup-go@v3 with: go-version: 1.18 @@ -37,34 +49,38 @@ jobs: # download packages - name: Cache Go Mod + if: needs.precheck.outputs.fileschanged == 'true' + id: modcache uses: actions/cache@v3 - id: cache with: path: ${{ steps.go-cache-paths.outputs.go-mod }} key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} - name: Run go mod download - if: steps.cache.outputs.cache-hit != 'true' + if: needs.precheck.outputs.fileschanged == 'true' && steps.modcache.outputs.cache-hit != 'true' run: go mod download # build the binary - name: Cache Go build + if: needs.precheck.outputs.fileschanged == 'true' + id: gocache uses: actions/cache@v3 - id: mybuild with: path: ${{ steps.go-cache-paths.outputs.go-build }} key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - name: Go build - if: steps.mybuild.outputs.cache-hit != 'true' + if: needs.precheck.outputs.fileschanged == 'true' && steps.gocache.outputs.cache-hit != 'true' run: go build -v ./... # Install gotestfmt - name: Set up gotestfmt + if: needs.precheck.outputs.fileschanged == 'true' run: go install github.com/haveyoudebuggedit/gotestfmt/v2/cmd/gotestfmt@latest # AWS creds - name: Configure AWS credentials from Test account + if: needs.precheck.outputs.fileschanged == 'true' uses: aws-actions/configure-aws-credentials@v1 with: role-to-assume: arn:aws:iam::951767375776:role/corso-testing-role @@ -72,8 +88,8 @@ jobs: aws-region: us-east-1 # run the tests - - run: echo "Running ${{ github.repository }} integration tests." - name: Integration Tests + if: needs.precheck.outputs.fileschanged == 'true' env: CLIENT_ID: ${{ secrets.CLIENT_ID }} CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} @@ -87,8 +103,8 @@ jobs: # Upload the original go test log as an artifact for later review. - name: Upload test log + if: needs.precheck.outputs.fileschanged == 'true' uses: actions/upload-artifact@v2 - if: always() with: name: test-log path: /tmp/gotest.log diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml index e90b57482..ffa5a1b3c 100644 --- a/.github/workflows/docgen.yml +++ b/.github/workflows/docgen.yml @@ -9,10 +9,14 @@ permissions: deployments: write jobs: + precheck: + uses: alcionai/corso/.github/workflows/_filechange_checker.yml@issue-744-alt + Generate-Markdown: + needs: precheck + if: needs.precheck.outputs.fileschanged == 'true' runs-on: ubuntu-latest steps: - - name: Repo Code Checkout uses: actions/checkout@v3 with: diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index a703845d7..635bdee37 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -6,9 +6,15 @@ on: permissions: contents: read packages: write + pull-requests: read jobs: + precheck: + uses: alcionai/corso/.github/workflows/_filechange_checker.yml@issue-744-alt + Per-SHA-Image: + needs: precheck + if: needs.precheck.outputs.fileschanged == 'true' runs-on: ubuntu-latest defaults: run: @@ -16,7 +22,6 @@ jobs: env: PLATFORMS: linux/amd64,linux/arm64 steps: - - name: Checkout repository uses: actions/checkout@v3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b8398adfe..8701b1186 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,9 +7,19 @@ on: permissions: contents: read + pull-requests: read + +# cancel currently running jobs if a new version of the branch is pushed +concurrency: + group: ci-linting-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: + precheck: + uses: alcionai/corso/.github/workflows/_filechange_checker.yml@issue-744-alt + Linting: + needs: precheck environment: Testing runs-on: ubuntu-latest defaults: @@ -21,39 +31,45 @@ jobs: uses: actions/checkout@v3 # Get values for cache paths to be used in later steps - - id: go-cache-paths + - name: Local Cache Setup + if: needs.precheck.outputs.fileschanged == 'true' + id: go-cache-paths run: | echo "::set-output name=go-build::$(go env GOCACHE)" echo "::set-output name=go-mod::$(go env GOMODCACHE)" - name: Golang Setup + if: needs.precheck.outputs.fileschanged == 'true' uses: actions/setup-go@v3 with: go-version: 1.18 - name: Cache Go Mod + if: needs.precheck.outputs.fileschanged == 'true' + id: modcache uses: actions/cache@v3 - id: cache with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} - name: Download package dependencies - if: steps.cache.outputs.cache-hit != 'true' + if: needs.precheck.outputs.fileschanged == 'true' && steps.modcache.outputs.cache-hit != 'true' run: go mod download - name: Cache Go build + if: needs.precheck.outputs.fileschanged == 'true' + id: gocache uses: actions/cache@v3 - id: mybuild with: path: ~/.cache/go-build key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - name: Build for Lint - if: steps.mybuild.outputs.cache-hit != 'true' + if: needs.precheck.outputs.fileschanged == 'true' && steps.gocache.outputs.cache-hit != 'true' run: go build ./... - name: Go Lint + if: needs.precheck.outputs.fileschanged == 'true' uses: golangci/golangci-lint-action@v3.2.0 with: version: v1.45.2 @@ -64,7 +80,9 @@ jobs: # check licenses - name: Get go-licenses + if: needs.precheck.outputs.fileschanged == 'true' run: go install github.com/google/go-licenses@latest - name: Run go-licenses + if: needs.precheck.outputs.fileschanged == 'true' run: go-licenses check github.com/alcionai/corso/src --ignore github.com/alcionai/corso/src \ No newline at end of file