|
| 1 | +name: Deploy CD |
| 2 | + |
| 3 | +on: |
| 4 | + |
| 5 | + # Run on push on production branches |
| 6 | + push: |
| 7 | + branches: |
| 8 | + # Production |
| 9 | + - main |
| 10 | + paths: |
| 11 | + # CI files |
| 12 | + - '.github/workflows/deploy.yml' |
| 13 | + - 'docker-compose.yml' |
| 14 | + - 'docker-compose.cicd.yml' |
| 15 | + - '.env' |
| 16 | + # Application files |
| 17 | + - 'app/**' |
| 18 | + |
| 19 | + # Run on manual triggers |
| 20 | + workflow_dispatch: |
| 21 | + |
| 22 | +# Set GITHUB_TOKEN permissions for the workflow |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +# Set workflow concurrency rules |
| 27 | +concurrency: |
| 28 | + group: ${{ github.workflow }} |
| 29 | + cancel-in-progress: true |
| 30 | + |
| 31 | +jobs: |
| 32 | + |
| 33 | + # Build job |
| 34 | + build: |
| 35 | + name: Build |
| 36 | + runs-on: ubuntu-latest |
| 37 | + timeout-minutes: 15 |
| 38 | + |
| 39 | + steps: |
| 40 | + |
| 41 | + # Steps dependencies |
| 42 | + |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + # Execution steps |
| 47 | + |
| 48 | + - name: Copy Git history in app source folder |
| 49 | + run: | |
| 50 | + # Copy app source code git history |
| 51 | + # Initialize Git repository in app source code directory |
| 52 | + ( |
| 53 | + cd app/app && |
| 54 | + rm -rf .git && |
| 55 | + git init -b main && |
| 56 | + git config receive.denyCurrentBranch ignore |
| 57 | + ) |
| 58 | + # Get Git history of app source code |
| 59 | + git subtree split --prefix=app/app -b app-history |
| 60 | + # Push Git history to app source code directory |
| 61 | + ( |
| 62 | + git remote add app ./app/app/.git && |
| 63 | + git push app app-history:main && |
| 64 | + git branch -D app-history && |
| 65 | + git remote remove app |
| 66 | + ) |
| 67 | +
|
| 68 | + - name: Pull dependencies |
| 69 | + run: | |
| 70 | + # docker compose pull --ignore-buildable |
| 71 | + docker compose \ |
| 72 | + -f ./docker-compose.yml -f ./docker-compose.cicd.yml \ |
| 73 | + --env-file .env \ |
| 74 | + pull --ignore-buildable |
| 75 | +
|
| 76 | + - name: Build for production |
| 77 | + env: |
| 78 | + GITHUB_REPOSITORY_URL: https://github.com/${{ github.repository }} |
| 79 | + GITHUB_SHA: ${{ github.sha }} |
| 80 | + BUILD_CHECK: "false" # Skip type checks |
| 81 | + run: | |
| 82 | + # docker compose build |
| 83 | + export DOCKER_UID="$(id -u)" |
| 84 | + docker compose \ |
| 85 | + -f ./docker-compose.yml -f ./docker-compose.cicd.yml \ |
| 86 | + --env-file .env \ |
| 87 | + build |
| 88 | +
|
| 89 | + - name: Copy application files |
| 90 | + run: | |
| 91 | + # docker compose up |
| 92 | + export DOCKER_UID="$(id -u)" |
| 93 | + docker compose \ |
| 94 | + -f ./docker-compose.yml -f ./docker-compose.cicd.yml \ |
| 95 | + --env-file .env \ |
| 96 | + up |
| 97 | +
|
| 98 | + - name: Upload GitHub Pages artifact |
| 99 | + uses: actions/upload-pages-artifact@v3 |
| 100 | + with: |
| 101 | + path: ./app/dist |
| 102 | + |
| 103 | + # Deploy job |
| 104 | + deploy: |
| 105 | + name: Deploy |
| 106 | + runs-on: ubuntu-latest |
| 107 | + timeout-minutes: 10 |
| 108 | + |
| 109 | + # Job dependencies |
| 110 | + needs: |
| 111 | + - build |
| 112 | + |
| 113 | + # Set GITHUB_TOKEN permissions for the job |
| 114 | + permissions: |
| 115 | + pages: write |
| 116 | + id-token: write |
| 117 | + |
| 118 | + # Set deployment environment |
| 119 | + environment: |
| 120 | + name: production |
| 121 | + url: ${{ steps.deployment.outputs.page_url }} |
| 122 | + |
| 123 | + steps: |
| 124 | + |
| 125 | + - name: Deploy to GitHub Pages |
| 126 | + id: deployment |
| 127 | + uses: actions/deploy-pages@v4 |
0 commit comments