Skip to content

Commit

Permalink
ci(gcp): deploy automatically when merging to main (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Sep 27, 2023
1 parent 1f4fc64 commit 7ed13d1
Show file tree
Hide file tree
Showing 27 changed files with 12,058 additions and 10,867 deletions.
38 changes: 38 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
/.git/
.gitignore

# Node.js dependencies:
/node_modules/

/.idea/
/.github/
/.husky/
/config/
/docker/
/scripts/
/tests/


/.editorconfig
/.eslintrc.js
/.gitattributes
/.nvmrc
/.releaserc.js
/.validate-branch-namerc.json
/CHANGELOG.md
/CONTRIBUTING.md
/LICENSE
/README.md
/sonar-project.properties
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}
- name: Build app ✨
run: npm run build
- name: Build app and check main file ✨
run: |
npm run build \
test dist/main.js
lint:
name: Lint 🔍
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ jobs:
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Release 🏷️
id: release
run: npx semantic-release

outputs:
new-release-published: ${{ steps.release.outputs.new-release-published }}
new-release-version: ${{ steps.release.outputs.new-release-version }}

all-tests:
name: All Tests 🧬
runs-on: ubuntu-latest
Expand Down Expand Up @@ -224,6 +229,59 @@ 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@v3
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
1 change: 1 addition & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ module.exports = {
},
],
"@semantic-release/github",
"semantic-release-export-data",
],
};
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
1. 🐺 [What is this API ?](#what-is-this-api)
2. 🃏 [Available roles](#available-roles)
3. 🔨 [Installation](#installation)
4. 💯 [Tests](#tests)
5. ☑️ [Code analysis and consistency](#code-analysis-and-consistency)
6. 📈 [Releases & Changelog](#versions)
7.[Misc commands](#misc-commands)
8. ©️ [License](#license)
9. ❤️ [Contributors](#contributors)
4. 🚀 [Build](#build)
5. 💯 [Tests](#tests)
6. ☑️ [Code analysis and consistency](#code-analysis-and-consistency)
7. 📈 [Releases & Changelog](#versions)
8.[Misc commands](#misc-commands)
9. ©️ [License](#license)
10. ❤️ [Contributors](#contributors)

## <a name="what-is-this-api">🐺 What is this API ?</a>
Werewolves Assistant API provides over HTTP requests a way of manage Werewolves games to help the game master.
Expand Down Expand Up @@ -75,6 +76,21 @@ npm run docker:dev:start

# Start test Docker containers (if you want to run the tests)
npm run docker:test:start

# Run the app in dev mode
npm run start:dev
```

## <a name="build">🚀 Build</a>

In order to build the app for production, run the following command :

```bash
# Build the app
npm run build

# Run the app in production mode
npm run start:prod
```

## <a name="tests">💯 Tests</a>
Expand Down
1 change: 1 addition & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime: nodejs20

0 comments on commit 7ed13d1

Please sign in to comment.