Skip to content

Commit

Permalink
Update CI/CD workflows (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiboux authored Nov 8, 2024
1 parent 2cd36a3 commit 4cd67d3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 39 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Check CI

on:
# Run on pull requests to primary branches
pull_request:
branches:
- master
- main
- dev
paths:
- '.github/workflows/check.yml'
- 'app/**'
- 'docker-compose*.yml'

# Run on manual triggers
workflow_dispatch:

# Set GITHUB_TOKEN permissions
permissions:
contents: read

# Set workflow concurrency rules
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

jobs:

# Build job
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 10

steps:

- name: Checkout
uses: actions/checkout@v4

- name: Build for production
env:
GITHUB_REPOSITORY_URL: https://github.com/${{ github.repository }}
GITHUB_SHA: ${{ github.sha }}
BUILD_CHECK: "true"
run: docker compose -f docker-compose.yml -f docker-compose.cicd.yml build

- name: Copy application files
run: docker compose -f docker-compose.yml -f docker-compose.cicd.yml run --rm app

- name: Check application files
run: |
[ -d ./app/dist ] && [ $(ls -1 ./app/dist | wc -l) -gt 0 ] \
&& echo "Application files found" \
|| ( echo "No application files found" && exit 1 )
46 changes: 8 additions & 38 deletions .github/workflows/pages.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
name: Deploy to GitHub Pages
name: Deploy CD

on:

# Run on push events on primary branches
# Run on push on primary branches
push:
branches:
- master
- dev
- main
paths:
- '.github/workflows/pages.yml'
- 'app/**'
- 'docker-compose*.yml'

# Run on pull request events to primary branches
pull_request:
branches:
- master
paths:
- '.github/workflows/pages.yml'
- '.github/workflows/deploy.yml'
- 'app/**'
- 'docker-compose*.yml'

# Run on manual triggers
workflow_dispatch:
inputs:
environment:
description: 'Workflow environment'
required: true
type: choice
options:
- development
- production
default: 'production'

# Set GITHUB_TOKEN permissions for the workflow
permissions:
contents: read

# Restrict concurrent deployments
# Set workflow concurrency rules
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
Expand All @@ -56,10 +38,11 @@ jobs:
uses: actions/checkout@v4

- name: Build for production
run: docker compose -f docker-compose.yml -f docker-compose.cicd.yml build
env:
GITHUB_REPOSITORY_URL: https://github.com/${{ github.repository }}
GITHUB_SHA: ${{ github.sha }}
BUILD_CHECK: "false"
run: docker compose -f docker-compose.yml -f docker-compose.cicd.yml build

- name: Copy application files
run: docker compose -f docker-compose.yml -f docker-compose.cicd.yml run --rm app
Expand All @@ -68,12 +51,6 @@ jobs:
run: sudo chown -R $USER:$USER ./app/dist

- name: Upload artifact
# Only run on:
# - Push events to `master`.
# - Manual triggers on `production` environment.
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/master') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
uses: actions/upload-pages-artifact@v3
with:
path: ./app/dist
Expand All @@ -88,19 +65,12 @@ jobs:
needs:
- build

# Only run on:
# - Push events to `master`.
# - Manual triggers on `production` environment.
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/master') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
# Set GITHUB_TOKEN permissions for the job
permissions:
pages: write
id-token: write

# Set the deployment environment
# Set deployment environment
environment:
name: production
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
3 changes: 2 additions & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ ARG GITHUB_SHA=""
ENV GITHUB_SHA=${GITHUB_SHA}

# Build application
RUN npm run build
ARG BUILD_CHECK=true
RUN [ "${BUILD_CHECK}" == "true" ] && npm run build || npm run build-only


# --
Expand Down
1 change: 1 addition & 0 deletions app/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"build-only": "astro build",
"preview": "astro preview",
"astro": "astro"
},
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
image: ${IMAGES_PREFIX:-app}-cicd:${DOCKER_TAG:-latest}
build:
target: app_prod_build
args:
BUILD_CHECK: ${BUILD_CHECK:-true}
# Deploy override
volumes:
- ./app/dist:/tmp/dist
Expand Down

0 comments on commit 4cd67d3

Please sign in to comment.