Skip to content

Commit

Permalink
feat: use shared cache in tests and always run all tests (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-fully-ported authored Sep 27, 2023
1 parent cf7f9f9 commit 1867269
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 56 deletions.
91 changes: 81 additions & 10 deletions .github/workflows/pr_push_checks_go.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,111 @@
name: Go PR Checks

on:
pull_request:
paths:
- '**.go'
- '**.mod'
- '**.sum'
- '.github/workflows/pr_push_checks_go.yaml'
- pull_request

concurrency:
group: pr-go-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
cache:
name: Setup cache
runs-on: ubuntu-latest
outputs:
go-changes: ${{ steps.changed-files.outputs.test_any_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed go files
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
*.go
*.mod
*.sum
**/*.go
**/*.mod
**/*.sum
- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done
- name: Setup Go Cache
uses: actions/cache@v3
if: steps.changed-files.outputs.test_any_changed == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: porter-go-${{ hashFiles('**/go.sum') }}
restore-keys: porter-go-
- uses: actions/setup-go@v4
if: steps.changed-files.outputs.test_any_changed == 'true'
with:
cache: false
go-version-file: go.mod
- name: Download Go Modules
if: steps.changed-files.outputs.test_any_changed == 'true'
run: go mod download

testing_matrix:
name: Running Go Tests
runs-on: ${{ matrix.os }}
needs: cache
strategy:
matrix:
os: [ubuntu-latest]
folder: [cli, api, cmd, internal, provisioner]
name: Running Go Tests
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup Go Cache
uses: actions/cache@v3
uses: actions/cache/restore@v3
if: needs.cache.outputs.go-changes == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: porter-go-${{ hashFiles('**/go.sum') }}
- uses: actions/setup-go@v4
if: needs.cache.outputs.go-changes == 'true'
with:
cache: false
go-version: '1.20.5'
go-version-file: go.mod
- name: Download Go Modules
if: needs.cache.outputs.go-changes == 'true'
run: go mod download
- name: Run Go tests
if: needs.cache.outputs.go-changes == 'true'
run: go test ./${{ matrix.folder }}/...

linting:
name: Go Linter
runs-on: ubuntu-latest
needs: cache
steps:
- uses: actions/checkout@v3
- name: Setup Go Cache
uses: actions/cache/restore@v3
if: needs.cache.outputs.go-changes == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: porter-go-${{ hashFiles('**/go.sum') }}
- uses: actions/setup-go@v4
if: needs.cache.outputs.go-changes == 'true'
with:
cache: false
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
if: needs.cache.outputs.go-changes == 'true'
with:
version: latest
args: -c .github/golangci-lint.yaml --verbose
skip-pkg-cache: true
only-new-issues: true # this is needed until the following is merged: https://github.com/golangci/golangci-lint-action/issues/820
41 changes: 0 additions & 41 deletions .github/workflows/pr_push_checks_go_lint.yaml

This file was deleted.

24 changes: 19 additions & 5 deletions .github/workflows/pr_push_checks_node.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Node PR Checks

on:
pull_request:
paths:
- 'dashboard/*'
- '.github/workflows/pr_push_checks_node.yaml'
- pull_request

concurrency:
group: pr-node-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -16,12 +13,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed dashboard files
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
dashboard/**
- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done
- name: Setup Node
uses: actions/setup-node@v3
if: steps.changed-files.outputs.test_any_changed == 'true'
with:
node-version: 16
- name: Setup NPM
if: steps.changed-files.outputs.test_any_changed == 'true'
working-directory: dashboard
run: |
# installing updated npm
Expand All @@ -38,10 +50,12 @@ jobs:
npm --version 2>&1 1>/dev/null
echo "npm $(npm --version) installed"
- name: Install NPM Dependencies
if: steps.changed-files.outputs.test_any_changed == 'true'
working-directory: dashboard
run: |
npm i --legacy-peer-deps
- name: Run NPM Build
if: steps.changed-files.outputs.test_any_changed == 'true'
working-directory: dashboard
run: |
npm run build

0 comments on commit 1867269

Please sign in to comment.