Skip to content

Commit

Permalink
chore: Workflow improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pigri committed Nov 6, 2024
1 parent 5c84320 commit 7d3f6e8
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 132 deletions.
42 changes: 17 additions & 25 deletions .github/workflows/cache-preview.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: cache-preview
name: Cache Service Preview

on:
pull_request:
Expand All @@ -10,60 +10,52 @@ on:
- .github/workflows/cache-preview.yaml
pull_request_review:
types: [submitted]
issue_comment:
types: [created]

jobs:
image-build:
runs-on: ubicloud-standard-2
if: |
(github.event_name == 'issue_comment' &&
contains(github.event.comment.body, 'test') &&
github.event.issue.pull_request != null &&
github.event.pull_request.changed_files > 0) ||
(github.event_name == 'pull_request_review' &&
github.event.review.state == 'approved' &&
github.event.pull_request.changed_files > 0)
if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved'
steps:
- uses: actions/checkout@v4

- name: Check for path changes
id: path-check
run: |
echo "Checking for changes in specified paths..."
git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E 'services/cache/|.github/workflows/cache-pull.yaml' || echo "no-changes"
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
cache:
- 'services/cache/**'
- '.github/workflows/cache-preview.yaml'
- name: Login to Github Packages
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.cache == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.cache == 'true'
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: 🏗 Setup repo
if: steps.path-check.outputs.result != 'no-changes'
uses: actions/checkout@v4

- name: Set up Docker Context for Buildx
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.cache == 'true'
run: docker context create builders

- name: Set up Docker Buildx
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.cache == 'true'
uses: docker/setup-buildx-action@v3
with:
version: latest
endpoint: builders

- name: Docker meta
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.cache == 'true'
id: cache
uses: docker/metadata-action@v5
with:
Expand All @@ -74,7 +66,7 @@ jobs:
type=raw,value=latest
- name: Build
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.cache == 'true'
uses: docker/build-push-action@v6
with:
context: services/cache
Expand Down
89 changes: 40 additions & 49 deletions .github/workflows/core-preview.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: core-preview
name: Core Service Preview

on:
pull_request:
Expand All @@ -12,117 +12,108 @@ on:
- .github/workflows/core-preview.yaml
pull_request_review:
types: [submitted]
issue_comment:
types: [created]

jobs:
core-unit-test:
if: |
(github.event_name == 'issue_comment' &&
contains(github.event.comment.body, 'test') &&
github.event.issue.pull_request != null &&
github.event.pull_request.changed_files > 0) ||
(github.event_name == 'pull_request_review' &&
github.event.review.state == 'approved' &&
github.event.pull_request.changed_files > 0)
if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved'
name: Core unit tests
runs-on: ubicloud-standard-2
strategy:
matrix:
go-version: [ '1.21', '1.22', '1.23' ]
steps:
- name: Check for path changes
id: path-check
run: |
echo "Checking for changes in specified paths..."
git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.go$|go\.mod|go\.sum|\.github/workflows/core-pull\.yaml' || echo "no-changes"
- uses: actions/checkout@v4
if: steps.path-check.outputs.result != 'no-changes'

- name: Check for path changes
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
core:
- '*.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/core-preview.yaml'
- name: Copy and rename config file
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
run: cp config_example.yaml config.yaml

- name: Setup Go ${{ matrix.go-version }}
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install dependencies
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
run: go get -v

- name: Run unit tests
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
run: ENV=test go test ./...

core-docker-build:
if: |
(github.event_name == 'issue_comment' &&
contains(github.event.comment.body, 'test') &&
github.event.issue.pull_request != null &&
github.event.pull_request.changed_files > 0) ||
(github.event_name == 'pull_request_review' &&
github.event.review.state == 'approved' &&
github.event.pull_request.changed_files > 0)
if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved'
runs-on: ubicloud-standard-2
steps:
- uses: actions/checkout@v4

- name: Check for path changes
id: path-check
run: |
echo "Checking for changes in specified paths..."
git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.go$|go\.mod|go\.sum|\.github/workflows/core-pull\.yaml' || echo "no-changes"
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
core:
- '*.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/core-preview.yaml'
- name: Login to Github Packages
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: 🏗 Setup repo
if: steps.path-check.outputs.result != 'no-changes'
uses: actions/checkout@v4

- name: Set up Docker Context for Buildx
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
run: docker context create builders

- name: Set up Docker Buildx
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
uses: docker/setup-buildx-action@v3
with:
version: latest
endpoint: builders

- name: Docker meta
if: steps.path-check.outputs.result != 'no-changes'
id: openshield
if: steps.changes.outputs.core == 'true'
id: cache
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/openshieldai/openshield/openshield
ghcr.io/openshieldai/openshield/cache
tags: |
type=sha
type=raw,value=latest
- name: Build
if: steps.path-check.outputs.result != 'no-changes'
if: steps.changes.outputs.core == 'true'
uses: docker/build-push-action@v6
with:
context: .
context: services/cache
platforms: linux/arm64,linux/amd64
push: false
tags: ${{ steps.openshield.outputs.tags }}
labels: ${{ steps.openshield.outputs.labels }}
tags: ${{ steps.cache.outputs.tags }}
labels: ${{ steps.cache.outputs.labels }}
Loading

0 comments on commit 7d3f6e8

Please sign in to comment.