Skip to content

Commit

Permalink
test frontend in build step
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed May 9, 2024
1 parent 510f332 commit d8bcc0b
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build GoCert
name: Build Frontend

on:
workflow_call:
Expand All @@ -10,23 +10,16 @@ jobs:
run:
working-directory: ui
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use npm
uses: actions/setup-node@v4

- name: Build frontend
run: |
npm install
npm run build
go-build:
runs-on: ubuntu-latest
needs: [nextjs-build]
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
- name: Upload frontend files
uses: actions/upload-artifact@v4
with:
go-version-file: "go.mod"

- name: Build
run: go build ./...
name: frontend-static-files
path: ui/out
21 changes: 21 additions & 0 deletions .github/workflows/build-gocert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build GoCert

on:
workflow_call:

jobs:
go-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: Build
run: go build ./...
32 changes: 32 additions & 0 deletions .github/workflows/build-rock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,39 @@ jobs:
uses: actions/checkout@v4
- uses: canonical/craft-actions/rockcraft-pack@main
id: rockcraft

- name: Install Skopeo
run: |
sudo snap install skopeo --edge --devmode
- name: Import the image to Docker registry
run: |
sudo skopeo --insecure-policy copy oci-archive:${{ steps.rockcraft.outputs.rock }} docker-daemon:gocert:latest
- name: Create files required by GoCert
run: |
printf 'keypath: "/etc/config/key.pem"\ncertpath: "/etc/config/cert.pem"\ndbpath: "/etc/config/certs.db"\nport: 3000\n' > config.yaml
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 1 -out cert.pem -subj "/CN=githubaction.example"
- name: Run the image
run: |
docker run -d -p 3000:3000 --name gocert gocert:latest
- name: Load config
run: |
docker cp key.pem gocert:/etc/config
docker cp cert.pem gocert:/etc/config
docker cp config.yaml gocert:/etc/config
docker exec gocert /bin/pebble push -p /etc/config/key.pem /etc/config/key.pem
docker exec gocert /bin/pebble push -p /etc/config/cert.pem /etc/config/cert.pem
docker exec gocert /bin/pebble push -p /etc/config/config.yaml /etc/config/config.yaml
docker restart gocert
- name: Check if GoCert is successfully running
id: test_image
run: |
sleep 30
curl -k https://localhost:3000 2>&1 | grep GoCert
- uses: actions/upload-artifact@v4
if: steps.test_image.outcome == 'success'
with:

name: rock
path: ${{ steps.rockcraft.outputs.rock }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: golangci-lint
uses: golangci/golangci-lint-action@v5
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: Go vet
run: go vet ./...
21 changes: 13 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ on:
- main

jobs:
build-gocert:
uses: ./.github/workflows/main-jobs/build-gocert.yaml
unit-test-frontend:
uses: ./.github/workflows/test-frontend.yaml
build-nextjs:
uses: ./.github/workflows/build-frontend.yaml
unit-test-gocert:
needs: [build-gocert]
uses: ./.github/workflows/main-jobs/test-gocert.yaml
needs: [build-nextjs]
uses: ./.github/workflows/test-gocert.yaml
go-vet:
needs: [build-gocert]
uses: ./.github/workflows/main-jobs/go-vet.yaml
needs: [build-nextjs]
uses: ./.github/workflows/go-vet.yaml
go-lint:
needs: [build-gocert]
uses: ./.github/workflows/main-jobs/go-lint.yaml
needs: [build-nextjs]
uses: ./.github/workflows/go-lint.yaml
build-gocert:
needs: [build-nextjs]
uses: ./.github/workflows/build-gocert.yaml
rock-build:
needs: [build-gocert, unit-test-gocert, go-vet, go-lint]
uses: ./.github/workflows/build-rock.yaml
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Unit Test Frontend

on:
workflow_call:

jobs:
nextjs-unit-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@v4
- name: Use npm
uses: actions/setup-node@v4

- name: Build frontend
run: |
npm install
npm run test
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@ on:
workflow_call:

jobs:
nextjs-unit-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@v3
- name: Use npm
uses: actions/setup-node@v4

- name: Build frontend
run: |
npm install
npm run test
go-unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"


- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: Unit tests
run: go test -cover ./...

18 changes: 8 additions & 10 deletions rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ platforms:

services:
gocert:
command: gocert
command: gocert [ -config /etc/config/config.yaml ]
override: replace
startup: enabled

parts:
frontend:
source: ./ui
plugin: npm
build-snaps:
- node/20/stable
override-build: |
npm install
npm run build
gocert:
source: .
plugin: go
source: .
source-type: local
build-snaps:
- go/1.22/stable
- node/20/stable
override-build: |
npm install --prefix ui
npm run build --prefix ui
craftctl default
stage-packages:
- ca-certificates_data
- libc6_libs

0 comments on commit d8bcc0b

Please sign in to comment.