From 1847ae3a91bea7b6e43bd182bc0dcd570fb74bda Mon Sep 17 00:00:00 2001 From: Da-Jin Chu Date: Sun, 17 Jan 2021 16:59:46 -0500 Subject: [PATCH 1/3] GitHub Releases with built code --- .github/workflows/deploy.yml | 77 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 089c01009..3e1a4d6a0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,45 +3,26 @@ name: Deploy Staging on: push: branches: - - master + - dc/release jobs: build: - name: Build Dist Branch + name: Create Release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - ref: "dist" - fetch-depth: 0 + - name: Checkout code + uses: actions/checkout@v2 + # ========= BUILD ======== # - uses: actions/setup-node@v1 with: node-version: "12" - - name: "set git bot commiter" - run: git config --global user.name "KOH Build Bot" && git config --global user.email "bot@khouryofficehours.com" - - name: "merge new changes into dist" - run: git merge origin/master - - run: echo "::set-output name=version::$(git rev-parse origin/master)" - id: pre-version - - uses: bahmutov/npm-install@v1 - run: yarn build env: NEXT_PUBLIC_APM_SERVER: ${{ secrets.ELASTIC_APM_SERVER_URL}} NEXT_PUBLIC_SERVICE_VERSION: ${{ steps.pre-version.outputs.version }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - ## Ensure no new changes have been pushed in the time we spent building - - run: git fetch && echo "::set-output name=version::$(git rev-parse origin/master)" - id: post-version - - if: steps.pre-version.outputs.version == steps.post-version.outputs.version - uses: EndBug/add-and-commit@v4 - with: - add: "packages" - author_name: KOH Build Bot - author_email: bot@khouryofficehours.com - message: "Added built files" - ref: "dist" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Zip everything + run: zip -r release.zip . -x ".git/*" ".github/*" ## Associate release with git commits, so Sentry can guess which commits caused errors - name: Create Sentry release uses: getsentry/action-release@v1 @@ -61,22 +42,42 @@ jobs: version: ${{ steps.pre-version.outputs.version }} environment: staging projects: khoury-office-hours khoury-office-hours-frontend + # Sourcemaps to Elastic APM - name: Upload Sourcemaps to Elastic APM run: yarn ts-node packages/app/scripts/uploadSourceMapToAPM.js env: ELASTIC_APM_SERVER_URL: ${{ secrets.ELASTIC_APM_SERVER_URL}} ELASTIC_APM_SECRET_TOKEN: ${{ secrets.ELASTIC_APM_SECRET_TOKEN }} SERVICE_VERSION: ${{ steps.pre-version.outputs.version }} - deploy: - needs: build - runs-on: ubuntu-latest - steps: - - name: Install SSH key - uses: shimataro/ssh-key-action@v2 + # ========== CREATE AND UPLOAD RELEASE =========== # + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - key: ${{ secrets.SSH_KEY }} - name: id_rsa - known_hosts: ${{ secrets.KNOWN_HOSTS }} - - uses: actions/checkout@v2 - - name: "pm2 deploy to staging" - run: "npx pm2 deploy infrastructure/prod/ecosystem.config.js staging update" + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./release.zip + asset_name: ${{ github.ref }}.zip + asset_content_type: application/zip + # deploy: + # needs: build + # runs-on: ubuntu-latest + # steps: + # - name: Install SSH key + # uses: shimataro/ssh-key-action@v2 + # with: + # key: ${{ secrets.SSH_KEY }} + # name: id_rsa + # known_hosts: ${{ secrets.KNOWN_HOSTS }} + # - uses: actions/checkout@v2 + # - name: "pm2 deploy to staging" + # run: "npx pm2 deploy infrastructure/prod/ecosystem.config.js staging update" From bce1892800492a111c24aa115dcd86befc7f0a3a Mon Sep 17 00:00:00 2001 From: Da-Jin Chu Date: Sun, 17 Jan 2021 17:01:31 -0500 Subject: [PATCH 2/3] install npm oopsah --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3e1a4d6a0..dd8e53c5c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,6 +16,7 @@ jobs: - uses: actions/setup-node@v1 with: node-version: "12" + - uses: bahmutov/npm-install@v1 - run: yarn build env: NEXT_PUBLIC_APM_SERVER: ${{ secrets.ELASTIC_APM_SERVER_URL}} From 3b9112c002e50dcac637aaeaa106e0bea41dcb86 Mon Sep 17 00:00:00 2001 From: Da-Jin Chu Date: Sun, 17 Jan 2021 17:09:35 -0500 Subject: [PATCH 3/3] use sha --- .github/workflows/deploy.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dd8e53c5c..2ca05e26c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -57,8 +57,9 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} + tag_name: ${{ github.sha }} + release_name: Release ${{ github.sha }} + draft: true - name: Upload Release Asset id: upload-release-asset uses: actions/upload-release-asset@v1 @@ -67,7 +68,7 @@ jobs: with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./release.zip - asset_name: ${{ github.ref }}.zip + asset_name: release.zip asset_content_type: application/zip # deploy: # needs: build