Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add app CI workflows #10

Merged
merged 30 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6ba4ad3
ci: add app CI workflows
JoshuaLicense Feb 13, 2024
7915155
ci: trigger
JoshuaLicense Feb 13, 2024
eec17c3
ci: trigger
JoshuaLicense Feb 13, 2024
b97f146
ci: remove app matrix for UI improvements
JoshuaLicense Feb 13, 2024
865ce39
ci: re-add matrix
JoshuaLicense Feb 13, 2024
918ce78
ci: checkout remote repo
JoshuaLicense Feb 13, 2024
43e80d4
ci: fix working directory
JoshuaLicense Feb 13, 2024
cbccfee
ci: fix PHP version
JoshuaLicense Feb 13, 2024
a98edc1
ci: add `fail-fast: false` to static analysis
JoshuaLicense Feb 14, 2024
4f63f77
ci: add Docker job as placeholder
JoshuaLicense Feb 14, 2024
cdcbf7a
ci: prefix artefacts with project name
JoshuaLicense Feb 14, 2024
b4c08d7
ci: correctly placeholder various parts in the pipeline
JoshuaLicense Feb 14, 2024
84d5d03
ci: improve granularity of CI workflow
JoshuaLicense Feb 26, 2024
49e63b5
fixup! ci: improve granularity of CI workflow
JoshuaLicense Feb 26, 2024
5a1bb8a
fixup! ci: improve granularity of CI workflow
JoshuaLicense Feb 26, 2024
eae42cd
ci: add `continue-on-error` until static analysis is fixed
JoshuaLicense Feb 26, 2024
462e950
ci: add default run directory to lint/package jobs
JoshuaLicense Feb 26, 2024
78b765b
ci: fix `git archive` command
JoshuaLicense Feb 26, 2024
f22c398
ci: attempt to cast `should-build-*-docker` in app workflow
JoshuaLicense Feb 26, 2024
f64e1fa
ci: add verbosity to static analysis to debug performance
JoshuaLicense Feb 26, 2024
84e14aa
Revert "ci: add verbosity to static analysis to debug performance"
JoshuaLicense Feb 26, 2024
a8297dd
ci: fix artefact name
JoshuaLicense Feb 26, 2024
8a594a8
ci: remove `xdebug` extension
JoshuaLicense Feb 26, 2024
8a3345d
ci: disable static analysis for sanity
JoshuaLicense Feb 26, 2024
19c3199
ci: revert CD workflow changes
JoshuaLicense Feb 26, 2024
63c81af
ci: fix tar.gz upload path
JoshuaLicense Feb 26, 2024
e7ff3ba
Merge branch 'main' into add-app-ci
JoshuaLicense Feb 26, 2024
3eabe72
ci: remove test files
JoshuaLicense Feb 26, 2024
4cb71dc
ci: fix Docker job conditional
JoshuaLicense Feb 26, 2024
92ec6a2
ci: add `concurrency` to Docker job
JoshuaLicense Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/actions/get-app-version/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Get app version

inputs:
project-path:
description: The root path of the app project
required: true
ref:
description: The commit reference to use as a starting point for the version
required: true
default: "HEAD"

outputs:
version:
description: The app version
value: ${{ steps.get-version.outputs.version }}

runs:
using: "composite"
steps:
- id: get-version
shell: bash
run: |
LATEST_APP_COMMIT=$(git rev-list -1 --abbrev-commit ${{ inputs.ref }} -- ${{ inputs.project-path }})

COMMIT_RELEASE_VERSION=$(git describe --tags --abbrev=0 $LATEST_APP_COMMIT 2>/dev/null) || true

LATEST_RELEASE=$(git describe --tags --abbrev=0 ${{ inputs.reference }} 2>/dev/null) || true

if [[ $COMMIT_RELEASE_VERSION == $LATEST_RELEASE ]]; then
TAG=$(git describe --tags --exact-match $LATEST_APP_COMMIT 2>/dev/null) || true

if [[ -n $TAG ]]; then
echo "version=release/$TAG" >> $GITHUB_OUTPUT
else
echo "version=$LATEST_APP_COMMIT" >> $GITHUB_OUTPUT
fi
else
echo "version=release/$LATEST_RELEASE" >> $GITHUB_OUTPUT
fi
133 changes: 133 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,54 @@ jobs:
name: Orchestrator
runs-on: ubuntu-latest
outputs:
should-build-app: ${{ steps.changed-api-files.outputs.any_changed == 'true' || steps.changed-selfserve-files.outputs.any_changed == 'true' || steps.changed-internal-files.outputs.any_changed == 'true' || null }}
should-build-docker: ${{ steps.changed-api-docker-files.outputs.any_changed == 'true' || steps.changed-selfserve-docker-files.outputs.any_changed == 'true' || steps.changed-internal-docker-files.outputs.any_changed == 'true' || null }}
should-build-api: ${{ steps.changed-api-files.outputs.any_changed == 'true' || null }}
should-build-selfserve: ${{ steps.changed-selfserve-files.outputs.any_changed == 'true' || null }}
should-build-internal: ${{ steps.changed-internal-files.outputs.any_changed == 'true' || null }}
should-build-api-docker: ${{ steps.changed-api-docker-files.outputs.any_changed == 'true' || steps.changed-api-files.outputs.any_changed == 'true' || null }}
should-build-selfserve-docker: ${{ steps.changed-selfserve-docker-files.outputs.any_changed == 'true' || steps.changed-selfserve-files.outputs.any_changed == 'true' || null }}
should-build-internal-docker: ${{ steps.changed-internal-docker-files.outputs.any_changed == 'true' || steps.changed-internal-files.outputs.any_changed == 'true' || null }}
should-build-docs: ${{ steps.changed-website-files.outputs.any_changed == 'true' || null }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: tj-actions/changed-files@v42
id: changed-api-files
with:
files: |
app/api/**
# since_last_remote_commit: true
- uses: tj-actions/changed-files@v42
id: changed-selfserve-files
with:
files: |
app/selfserve/**
# since_last_remote_commit: true
- uses: tj-actions/changed-files@v42
id: changed-internal-files
with:
files: |
app/internal/**
- uses: tj-actions/changed-files@v42
id: changed-api-docker-files
with:
files: |
infra/docker/api/**
# since_last_remote_commit: true
- uses: tj-actions/changed-files@v42
id: changed-selfserve-docker-files
with:
files: |
infra/docker/selfserve/**
# since_last_remote_commit: true
- uses: tj-actions/changed-files@v42
id: changed-internal-docker-files
with:
files: |
infra/docker/internal/**
# since_last_remote_commit: true
- uses: tj-actions/changed-files@v42
id: changed-website-files
with:
Expand All @@ -34,3 +77,93 @@ jobs:
deploy: false
permissions:
contents: write

get-app-versions:
name: Get latest app version
needs:
- orchestrator
runs-on: ubuntu-latest
outputs:
api: ${{ steps.api-version.outputs.version }}
selfserve: ${{ steps.selfserve-version.outputs.version }}
internal: ${{ steps.internal-version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- id: api-version
uses: ./.github/actions/get-app-version
with:
project-path: app/api
- id: selfserve-version
uses: ./.github/actions/get-app-version
with:
project-path: app/selfserve
- id: internal-version
uses: ./.github/actions/get-app-version
with:
project-path: app/internal
- name: Add to summary
run: |
echo "#### App versions:" >> $GITHUB_STEP_SUMMARY
echo "**API**: \`${{ steps.api-version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Selfserve**: \`${{ steps.selfserve-version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Internal**: \`${{ steps.internal-version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY

app:
name: App
concurrency:
group: app-${{ matrix.project }}-${{ needs.get-app-versions.outputs[matrix.project] }}
needs:
- orchestrator
- get-app-versions
if: ${{ needs.orchestrator.outputs.should-build-app || needs.orchestrator.outputs.should-build-docker }}
strategy:
fail-fast: false
matrix:
project:
- api
- selfserve
- internal
exclude:
- project: ${{ (needs.orchestrator.outputs.should-build-api || needs.orchestrator.outputs.should-build-api-docker) && 'ignored' || 'api' }}
- project: ${{ (needs.orchestrator.outputs.should-build-selfserve || needs.orchestrator.outputs.should-build-selfserve-docker) && 'ignored' || 'selfserve' }}
- project: ${{ (needs.orchestrator.outputs.should-build-internal || needs.orchestrator.outputs.should-build-internal-docker) && 'ignored' || 'internal' }}
uses: ./.github/workflows/php.yaml
with:
project: ${{ matrix.project }}
should-upload-artefact: ${{ !!needs.orchestrator.outputs[format('should-build-{0}-docker', matrix.project)] }}
artefact-name: app-${{ matrix.project}}-${{ needs.get-app-versions.outputs[matrix.project] }}
retention-days: 1
permissions:
contents: read

docker:
name: Docker
concurrency:
group: docker-${{ matrix.project }}-${{ needs.get-app-versions.outputs[matrix.project] }}
needs:
- orchestrator
- get-app-versions
- app
if: ${{ always() && !cancelled() && !failure() && needs.orchestrator.outputs.should-build-docker }}
strategy:
fail-fast: false
matrix:
project:
- api
- selfserve
- internal
exclude:
- project: ${{ needs.orchestrator.outputs.should-build-api-docker && 'ignored' || 'api' }}
- project: ${{ needs.orchestrator.outputs.should-build-selfserve-docker && 'ignored' || 'selfserve' }}
- project: ${{ needs.orchestrator.outputs.should-build-internal-docker && 'ignored' || 'internal' }}
uses: ./.github/workflows/docker.yaml
with:
project: ${{ matrix.project }}
app-artefact-name: app-${{ matrix.project}}-${{ needs.get-app-versions.outputs[matrix.project] }}
should-upload-artefact-to-ecr: false
permissions:
contents: read
id-token: write
67 changes: 67 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Docker

on:
workflow_call:
inputs:
ref:
type: string
required: false
project:
type: string
required: true
should-upload-artefact-to-ecr:
type: boolean
required: true
default: false
app-artefact-name:
type: string
required: true

jobs:
check-ecr:
name: Check ECR
if: ${{ inputs.should-upload-artefact-to-ecr }}
runs-on: ubuntu-latest
outputs:
image-exists: ${{ steps.check-ecr.outputs.exists }}
env:
PROJECT: ${{ inputs.project }}
OBJECT_PREFIX: ${{ inputs.app-artefact-name }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.TF_OIDC_ROLE }}
aws-region: ${{ vars.TF_AWS_REGION }}
- name: Check if image already exists in ECR
id: check-ecr
# Check if the image already exists in ECR, so we don't have to build it again.
run: exit 0

lint:
name: Lint
needs:
- check-ecr
runs-on: ubuntu-latest
if: ${{ always() && (needs.check-ecr.result == 'skipped' || !needs.check-ecr.outputs.image-exists) }}
steps:
- name: Lint
run: exit 0

build:
name: Build
needs:
- check-ecr
runs-on: ubuntu-latest
if: ${{ always() && (needs.check-ecr.result == 'skipped' || !needs.check-ecr.outputs.image-exists) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || null }}
path: infra/docker/${{ inputs.project }}
- uses: actions/download-artifact@v4
with:
name: ${{ inputs.app-artefact-name }}
path: app/${{ inputs.project }}
- name: Build
run: exit 0
Loading