feat(gha): deploy to delivery repository #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
issue_comment: | |
types: | |
- created | |
- edited | |
defaults: | |
run: | |
shell: bash -euxo pipefail {0} | |
jobs: | |
should-skip: | |
name: Should skip? | |
runs-on: ubuntu-22.04 | |
outputs: | |
skip: ${{ steps.should-skip.outputs.skip }} | |
steps: | |
- run: | | |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
echo "skip=false" >> "$GITHUB_OUTPUT" | |
elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then | |
if [[ -z "${{ github.event.issue.pull_request.number }}" ]]; then | |
COMMENT="${{ github.event.comment.body }}" | |
if [[ "${COMMENT}" =~ ^/deploy$ ]]; then | |
echo "skip=false" >> "$GITHUB_OUTPUT" | |
else | |
echo "skip=true" >> "$GITHUB_OUTPUT" | |
fi | |
else | |
echo "skip=false" >> "$GITHUB_OUTPUT" | |
fi | |
backend-unit-tests: | |
name: Backend Unit Tests | |
runs-on: ubuntu-22.04 | |
needs: should-skip | |
if: ${{ needs.should-skip.outputs.skip }} == "false" | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version-file: backend/go.mod | |
cache-dependency-path: backend/go.sum | |
- run: go test ./... | |
working-directory: backend | |
build-backend-image: | |
name: Build Backend | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 15 | |
needs: should-skip | |
if: ${{ needs.should-skip.outputs.skip }} == "false" | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- 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/metadata-action@v4 | |
id: meta | |
with: | |
images: ghcr.io/${{ github.repository }}/backend | |
tags: | | |
type=sha,prefix=,suffix=,format=short | |
type=sha,prefix=,suffix=,format=long | |
type=ref,event=branch | |
type=ref,event=pr | |
- uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: backend | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
build-frontend-image: | |
name: Build Frontend | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 15 | |
needs: should-skip | |
if: ${{ needs.should-skip.outputs.skip }} == "false" | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- 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/metadata-action@v4 | |
id: meta | |
with: | |
images: ghcr.io/${{ github.repository }}/frontend | |
tags: | | |
type=sha,prefix=,suffix=,format=short | |
type=sha,prefix=,suffix=,format=long | |
type=ref,event=branch | |
type=ref,event=pr | |
- uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: frontend | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
build-neo4j-image: | |
name: Build Neo4j | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 15 | |
needs: should-skip | |
if: ${{ needs.should-skip.outputs.skip }} == "false" | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- 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/metadata-action@v4 | |
id: meta | |
with: | |
images: ghcr.io/${{ github.repository }}/neo4j | |
tags: | | |
type=sha,prefix=,suffix=,format=short | |
type=sha,prefix=,suffix=,format=long | |
type=ref,event=branch | |
type=ref,event=pr | |
- uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: deploy/base/neo4j | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
build-migrations-image: | |
name: Build Migrations | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 15 | |
needs: should-skip | |
if: ${{ needs.should-skip.outputs.skip }} == "false" | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- 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/metadata-action@v4 | |
id: meta | |
with: | |
images: ghcr.io/${{ github.repository }}/migrations | |
tags: | | |
type=sha,prefix=,suffix=,format=short | |
type=sha,prefix=,suffix=,format=long | |
type=ref,event=branch | |
type=ref,event=pr | |
- uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: migrations | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
deploy-to-environment: | |
name: Deploy to environment | |
needs: [ build-backend-image, build-frontend-image, build-neo4j-image, build-migrations-image ] | |
uses: arikkfir/delivery/.github/workflows/deploy-to-environment.yml@main | |
with: | |
branch: ${{ github.ref_name }} | |
images: |- | |
ghcr.io/${{ github.repository }}/backend: ${{ github.sha }} | |
ghcr.io/${{ github.repository }}/frontend: ${{ github.sha }} | |
ghcr.io/${{ github.repository }}/migrations: ${{ github.sha }} | |
ghcr.io/${{ github.repository }}/neo4j: ${{ github.sha }} | |
secrets: inherit |