Test & Deploy #3277
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test & Deploy | |
on: [push, workflow_dispatch] | |
env: | |
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | |
jobs: | |
test_back: | |
runs-on: ubuntu-latest | |
timeout-minutes: 25 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Setup timezone | |
uses: zcong1993/setup-timezone@master | |
with: | |
timezone: Europe/Paris | |
- name: Install api deps | |
run: | | |
cd run | |
npm install | |
- name: Run api tests | |
run: | | |
cd run | |
npm run test tests/ | |
- name: Install pm2 server deps | |
run: | | |
cd pm2-server | |
npm install | |
- name: Run pm2 server tests | |
run: | | |
cd pm2-server | |
npm run test | |
test_front: | |
runs-on: ubuntu-latest | |
timeout-minutes: 25 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Setup timezone | |
uses: zcong1993/setup-timezone@master | |
with: | |
timezone: Europe/Paris | |
- name: Install deps | |
run: yarn | |
- name: Run tests | |
run: npm run test:unit | |
env: | |
TZ: CET | |
create_release: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [test_front, test_back] | |
runs-on: ubuntu-latest | |
outputs: | |
current_version: ${{ steps.get_changelog.outputs.version }} | |
changes: ${{ steps.get_changelog.outputs.changes }} | |
release_name: ${{ steps.get_release.outputs.release_name }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get tag | |
id: get_tag | |
run: echo "current_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Get release name | |
id: get_release | |
run: echo "release_name=ethernal@${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Get Changelog Entry | |
id: get_changelog | |
uses: mindsers/changelog-reader-action@v2 | |
with: | |
validation_depth: 10 | |
version: ${{ steps.get_tag.outputs.current_version }} | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
body: ${{ steps.get_changelog.outputs.changes }} | |
tag: ${{ steps.get_changelog.outputs.version }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
publish_docker_images: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [create_release] | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push backend | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
target: prod_all | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ethernal:latest,${{ secrets.DOCKERHUB_USERNAME }}/ethernal:v${{ needs.create_release.outputs.current_version }} | |
- name: Build and push PM2 server | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile.pm2 | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ethernal-pm2:latest,${{ secrets.DOCKERHUB_USERNAME }}/ethernal-pm2:v${{ needs.create_release.outputs.current_version }} | |
deploy_front: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [create_release] | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Install deps & build | |
run: yarn && yarn build | |
env: | |
VUE_APP_FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }} | |
VUE_APP_FIREBASE_AUTH_DOMAIN: ${{ secrets.FIREBASE_AUTH_DOMAIN }} | |
VUE_APP_FIREBASE_DATABASE_URL: ${{ secrets.FIREBASE_DATABASE_URL }} | |
VUE_APP_FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} | |
VUE_APP_FIREBASE_STORAGE_BUCKET: ${{ secrets.FIREBASE_STORAGE_BUCKET }} | |
VUE_APP_MESSAGING_SENDER_ID: ${{ secrets.MESSAGING_SENDER_ID }} | |
VUE_APP_FIREBASE_APP_ID: ${{ secrets.VUE_APP_FIREBASE_APP_ID }} | |
VUE_APP_API_ROOT: ${{ secrets.API_ROOT }} | |
VUE_APP_ENABLE_BILLING: true | |
VUE_APP_MAIN_DOMAIN: ${{ secrets.MAIN_DOMAIN }} | |
VUE_APP_PUSHER_KEY: ${{ secrets.PUSHER_KEY }} | |
VUE_APP_ENABLE_ANALYTICS: true | |
VUE_APP_ENABLE_MARKETING: true | |
VUE_APP_ENABLE_DEMO: true | |
VUE_APP_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }} | |
VUE_APP_POSTHOG_API_HOST: ${{ secrets.POSTHOG_API_HOST }} | |
VUE_APP_SOKETI_HOST: ${{ secrets.SOKETI_HOST }} | |
VUE_APP_SOKETI_PORT: ${{ secrets.SOKETI_PORT }} | |
VUE_APP_SOKETI_FORCE_TLS: ${{ secrets.SOKETI_FORCE_TLS }} | |
VUE_APP_FEEDBACK_FIN_ENDPOINT: ${{ secrets.FEEDBACK_FIN_ENDPOINT }} | |
VUE_APP_VERSION: ${{ needs.create_release.outputs.current_version }} | |
VUE_APP_SENTRY_DSN_SECRET: ${{ secrets.SENTRY_DSN_SECRET }} | |
VUE_APP_SENTRY_DSN_PROJECT_ID: ${{ secrets.SENTRY_DSN_PROJECT_ID }} | |
COMMIT_REF: ${{ github.sha }} | |
SENTRY_URL: ${{ secrets.SENTRY_URL }} | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
SENTRY_ORG: ${{ secrets.SENTRY_ORG }} | |
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} | |
SENTRY_RELEASE: ${{ needs.create_release.outputs.release_name }} | |
- uses: nwtgck/actions-netlify@v2.0.0 | |
id: netlify_deploy | |
with: | |
publish-dir: './dist' | |
deploy-message: 'Deploying commit ${{ github.sha }}' | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
- name: Store deploy id | |
id: store_deploy_id | |
run: | | |
ID=$(echo ${{ steps.netlify_deploy.outputs.deploy-url }} | sed 's/https:\/\/\(.*\)--tryethernal\.netlify\.app/\1/') | |
echo $ID > deploy_id.txt | |
- name: Upload deploy ID | |
uses: actions/upload-artifact@v3 | |
with: | |
name: netlify_deploy_id | |
path: deploy_id.txt | |
deploy_back: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [create_release] | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup credentials | |
run: | | |
echo "$GCLOUD_CREDENTIALS" >> ethernal-95a14-19f78a7e26cc.json | |
shell: bash | |
env: | |
GCLOUD_CREDENTIALS: ${{ secrets.GCLOUD_CREDENTIALS }} | |
- uses: superfly/flyctl-actions/setup-flyctl@master | |
- name: Build & push backend image | |
run: | | |
flyctl auth docker | |
docker build --target prod_back -t registry.fly.io/ethernal:${{ github.sha }} -f Dockerfile . | |
docker push registry.fly.io/ethernal:${{ github.sha }} | |
- name: Build & push PM2 server image | |
run: | | |
flyctl auth docker | |
docker build --target prod -t registry.fly.io/ethernal-pm2:${{ github.sha }} -f Dockerfile.pm2 . | |
docker push registry.fly.io/ethernal-pm2:${{ github.sha }} | |
release_front: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [deploy_front, deploy_back] | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Download Deploy ID | |
uses: actions/download-artifact@v3 | |
with: | |
name: netlify_deploy_id | |
- name: Release deploy | |
run: | | |
deploy_id=$(cat deploy_id.txt) | |
curl -H "Authorization: Bearer ${{ secrets.NETLIFY_AUTH_TOKEN }}" -X POST -d {} https://api.netlify.com/api/v1/sites/${{ secrets.NETLIFY_SITE_ID }}/deploys/$deploy_id/restore | |
release_back: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [deploy_front, deploy_back, create_release] | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: superfly/flyctl-actions/setup-flyctl@master | |
- name: Update version | |
run: | | |
flyctl secrets set VERSION=${{ needs.create_release.outputs.current_version }} --stage -a ethernal | |
flyctl secrets set VERSION=${{ needs.create_release.outputs.current_version }} --stage -a ethernal-pm2 | |
- name: Release backend | |
run: flyctl deploy -c fly.toml -i registry.fly.io/ethernal:${{ github.sha }} | |
- name: Release PM2 server | |
run: flyctl deploy -c fly.pm2.toml -i registry.fly.io/ethernal-pm2:${{ github.sha }} | |
- name: Release Soketi server | |
run: flyctl deploy -c fly.soketi.toml |