Skip to content

Commit

Permalink
ci(deploy-to-production): deployment to production is triggered on ta…
Browse files Browse the repository at this point in the history
…g creation (#667)

Closes #571
  • Loading branch information
antoinezanardi committed Nov 27, 2023
1 parent 415ca6f commit b269b11
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 57 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/deploy-to-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 🛰️ Deploy To Production Workflow

on:
release:
types: [created]

jobs:
deploy:
name: Deploy to production 🛰️
runs-on: ubuntu-latest
steps:
- name: Setup GitHub repository 🔧
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
fetch-depth: 0
fetch-tags: true

- name: Setup NodeJS ✨
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Restore npm dependencies from cache 🥡
uses: actions/cache/restore@v3
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Write production .env file 📝
run: |
npx rimraf env/.env.production
echo ENVIRONMENT="production" >> env/.env.production
echo DATABASE_HOST="${{ secrets.PRODUCTION_DATABASE_HOST }}" >> env/.env.production
echo DATABASE_NAME="${{ secrets.PRODUCTION_DATABASE_NAME }}" >> env/.env.production
echo DATABASE_USERNAME="${{ secrets.PRODUCTION_DATABASE_USERNAME }}" >> env/.env.production
echo DATABASE_PASSWORD="${{ secrets.PRODUCTION_DATABASE_PASSWORD }}" >> env/.env.production
cat env/.env.production
- name: Build app ✨
run: npm run build

- name: Auth to GCP ☁️
uses: 'google-github-actions/auth@v1'
with:
credentials_json: ${{ secrets.PRODUCTION_GCP_SA_KEY }}

- name: Transform and format version for GCP ♻️
id: format-version-for-gcp
run: |
version=${{ github.event.release.tag_name }}
version=${version//./-}
echo "FORMATTED_VERSION_FOR_GCP=${version}" >> $GITHUB_OUTPUT
- name: Deploy to production 🛰️
uses: 'google-github-actions/deploy-appengine@v1'
with:
project_id: ${{ secrets.PRODUCTION_GCP_PROJECT_ID }}
flags: "--version=${{ steps.format-version-for-gcp.outputs.FORMATTED_VERSION_FOR_GCP }}"
5 changes: 3 additions & 2 deletions .github/workflows/lint-pr-name-into-develop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🔃 Lint Pull Request Name Into Develop Workflow
name: 🔃 Lint PR Name Into Develop Workflow

on:
pull_request:
Expand All @@ -9,6 +9,7 @@ on:
- edited
- reopened
- synchronize

jobs:
develop-pr-lint:
name: Lint Pull Request Name 🔃
Expand All @@ -22,4 +23,4 @@ jobs:
on-failed-regex-fail-action: true
on-failed-regex-create-review: true
on-failed-regex-request-changes: false
on-failed-regex-comment: "[Auto-generated comment] Your Pull Request name is not compliant to conventional commits : ```%regex%```!"
on-failed-regex-comment: "[Auto-generated comment] Your Pull Request name is not compliant to conventional commits : ```%regex%```!"
2 changes: 1 addition & 1 deletion .github/workflows/push-on-develop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ⛵️ Push on develop branch Workflow
name: ⛵️ Push On Develop Branch Workflow

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🚀 Release Workflow
name: 🏷️ Release Creation Workflow

on:
push:
Expand Down Expand Up @@ -229,59 +229,6 @@ jobs:
- name: Stop Docker containers 🐳
run: npm run docker:test:stop

deploy:
name: Deploy to production 🚀
runs-on: ubuntu-latest
needs:
- release
steps:
- name: Setup GitHub repository 🔧
uses: actions/checkout@v4

- name: Setup NodeJS ✨
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Restore npm dependencies from cache 🥡
uses: actions/cache/restore@v3
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Write production .env file 📝
run: |
npx rimraf env/.env.production
echo ENVIRONMENT="production" >> env/.env.production
echo DATABASE_HOST="${{ secrets.PRODUCTION_DATABASE_HOST }}" >> env/.env.production
echo DATABASE_NAME="${{ secrets.PRODUCTION_DATABASE_NAME }}" >> env/.env.production
echo DATABASE_USERNAME="${{ secrets.PRODUCTION_DATABASE_USERNAME }}" >> env/.env.production
echo DATABASE_PASSWORD="${{ secrets.PRODUCTION_DATABASE_PASSWORD }}" >> env/.env.production
cat env/.env.production
- name: Build app ✨
run: npm run build

- name: Auth to GCP ☁️
uses: 'google-github-actions/auth@v1'
with:
credentials_json: ${{ secrets.PRODUCTION_GCP_SA_KEY }}

- name: Transform and format version for GCP ♻️
id: format-version-for-gcp
run: |
version=${{ needs.release.outputs.new-release-version }}
version=${version//./-}
echo "FORMATTED_VERSION_FOR_GCP=${version}" >> $GITHUB_OUTPUT
- name: Deploy to production 🚀
uses: 'google-github-actions/deploy-appengine@v1'
with:
project_id: ${{ secrets.PRODUCTION_GCP_PROJECT_ID }}
flags: "--version=${{ steps.format-version-for-gcp.outputs.FORMATTED_VERSION_FOR_GCP }}"

badges:
name: Generate Badges 💠
runs-on: ubuntu-latest
Expand Down

0 comments on commit b269b11

Please sign in to comment.