Skip to content

Commit

Permalink
refactor(gha): build,e2e to sep. workflow (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
arikkfir committed Sep 22, 2023
1 parent ced6e35 commit 305f743
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 100 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: End-to-end Testing

on:
deployment_status:

defaults:
run:
shell: bash -exuo pipefail {0}

jobs:

dump:
name: Get ref
runs-on: ubuntu-22.04
outputs:
env: ${{ steps.env.outputs.name }}
steps:
- run: |
cat > f <<EOF
${{ toJson(github.event) }}
EOF
cat f
114 changes: 14 additions & 100 deletions .github/workflows/pr_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,135 +5,49 @@ on:
types:
- opened
- synchronize
push:
branches:
- main

defaults:
run:
shell: bash -exuo pipefail {0}

jobs:

get-ref:
get-env:
name: Get ref
runs-on: ubuntu-22.04
outputs:
sha: ${{ steps.values.outputs.sha }}
env: ${{ steps.env.outputs.name }}
ref: ${{ steps.values.outputs.ref }}
steps:
- id: env
uses: arikkfir/delivery-env-name@v1
with:
branch: ${{ github.event.pull_request.head.ref || github.ref_name }}
- id: values
run: |
echo "ref=${{ github.event.pull_request.head.ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
echo "sha=${{ github.event.pull_request.head.sha || github.sha }}" >> "$GITHUB_OUTPUT"
backend-format:
name: Backend Code Format
needs: get-ref
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.get-ref.outputs.sha }}
- uses: actions/setup-go@v4
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- run: |
go fmt ./... | tee output.txt
if [[ -s output.txt ]]; then
echo "Incorrect Go formatting detected."
exit 1
fi
working-directory: backend
backend-unit-tests:
name: Backend Unit Tests
needs: get-ref
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.get-ref.outputs.sha }}
- uses: actions/setup-go@v4
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- run: go test ./...
env:
CGO_ENABLED: "0"
GO111MODULE: "on"
GOOS: linux
GOARCH: amd64
working-directory: backend

docker:
name: Build ${{ matrix.image }} image
needs: get-ref
runs-on: ubuntu-22.04
timeout-minutes: 30
strategy:
matrix:
image: [ backend, frontend, neo4j, migrations ]
fail-fast: false
permissions:
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.get-ref.outputs.sha }}
- if: matrix.image == 'frontend'
run: |-
cat > frontend/apply-patches.sh <<PATCHES_EOF
${{ secrets.FRONTEND_PATCHES }}
PATCHES_EOF
- uses: docker/setup-buildx-action@v2
with:
install: true
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=gha,scope=${{ needs.get-ref.outputs.ref }}-${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ needs.get-ref.outputs.ref }}-${{ matrix.image }}
context: ${{ matrix.image }}
push: true
tags: ghcr.io/${{ github.repository }}/${{ matrix.image }}:${{ needs.get-ref.outputs.sha }}
branch: ${{ github.event.pull_request.head.ref }}

deploy:
name: Deploy
needs: get-ref
needs: get-env
runs-on: ubuntu-22.04
environment: ${{ needs.get-ref.outputs.env }}
environment: ${{ needs.get-env.outputs.env }}
steps:
- uses: arikkfir/deploy@main
with:
repository: greenstar
branch: ${{ needs.get-ref.outputs.ref }}
sha: ${{ needs.get-ref.outputs.sha }}
environment: ${{ needs.get-ref.outputs.env }}
branch: ${{ github.event.pull_request.head.ref }}
sha: ${{ github.event.pull_request.head.sha }}
environment: ${{ needs.get-env.outputs.env }}
token: ${{ secrets.ARIKKFIR_GHA_AUTOMATION }}

e2e-tests:
name: End-to-end Tests
needs: [ get-ref, deploy ]
needs: [ get-env, deploy ]
runs-on: ubuntu-22.04
container:
image: mcr.microsoft.com/playwright:v1.37.1-jammy
steps:
- run: apt-get update && apt-get install -y patch
- uses: actions/checkout@v4
with:
ref: ${{ needs.get-ref.outputs.sha }}
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3
with:
node-version: 20.x
Expand All @@ -150,7 +64,7 @@ jobs:
DESCOPE_PROJECT_ID: ${{ secrets.DESCOPE_PROJECT_ID }}
DESCOPE_MANAGEMENT_KEY: ${{ secrets.DESCOPE_MANAGEMENT_KEY }}
DESCOPE_TENANT_ADMIN_ACCESS_KEY: ${{ secrets.DESCOPE_TENANT_ADMIN_ACCESS_KEY }}
ENV_NAME: ${{ needs.get-ref.outputs.env }}
ENV_NAME: ${{ needs.get-env.outputs.env }}
- uses: actions/upload-artifact@v3
if: success() || (failure() && steps.test.conclusion == 'failure')
with:
Expand All @@ -163,7 +77,7 @@ jobs:

e2e-report:
name: End-to-end Report
needs: [ get-ref, e2e-tests ]
needs: [ get-env, e2e-tests ]
if: success() || (failure() && needs.e2e-tests.result == 'failure')
runs-on: ubuntu-22.04
permissions:
Expand Down Expand Up @@ -210,9 +124,9 @@ jobs:
|| gh pr comment --repo "${REPOSITORY}" "${PR}" --body-file comment.txt
fi
env:
ENV_NAME: ${{ needs.get-ref.outputs.env }}
ENV_NAME: ${{ needs.get-env.outputs.env }}
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number || github.event.issue.number }}
PR: ${{ github.event.pull_request.number }}
REPOSITORY: ${{ github.repository }}
RESULT: ${{ needs.e2e-tests.result }}
SHA: ${{ needs.get-ref.outputs.sha }}
SHA: ${{ github.event.pull_request.head.sha }}
84 changes: 84 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Push

on:
push:
branches:
- '*'

defaults:
run:
shell: bash -exuo pipefail {0}

jobs:

backend-format:
name: Backend Code Format
needs: get-ref
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/setup-go@v4
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- run: go fmt ./...
working-directory: backend

backend-unit-tests:
name: Backend Unit Tests
needs: get-ref
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- uses: actions/setup-go@v4
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- run: go test ./...
env:
CGO_ENABLED: "0"
GO111MODULE: "on"
GOOS: linux
GOARCH: amd64
working-directory: backend

docker:
name: Build ${{ matrix.image }} image
needs: get-ref
runs-on: ubuntu-22.04
timeout-minutes: 30
strategy:
matrix:
image: [ backend, frontend, neo4j, migrations ]
fail-fast: false
permissions:
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- if: matrix.image == 'frontend'
run: |-
cat > frontend/apply-patches.sh <<PATCHES_EOF
${{ secrets.FRONTEND_PATCHES }}
PATCHES_EOF
- uses: docker/setup-buildx-action@v2
with:
install: true
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=gha,scope=${{ github.ref_name }}-${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ matrix.image }}
context: ${{ matrix.image }}
push: true
tags: ghcr.io/${{ github.repository }}/${{ matrix.image }}:${{ github.sha }}

0 comments on commit 305f743

Please sign in to comment.