From 7df1a2899da60d5057ccc2c1928b08c4dc6d9cd4 Mon Sep 17 00:00:00 2001 From: Heronimus Adie Date: Wed, 3 Apr 2024 00:21:36 +0700 Subject: [PATCH] ci: add linter and release workflow, remove manual vercel deployment (#24) * ci: remove manual vercel deployment workflow * ci: separate build workflow * ci: add linter ci * ci: add release ci * ci: release workflow -- fix path * ci: release workflow -- use tag name on zip file * fix typo workflow name * ci: add workflow_call on build.yaml * fix build release zip path * test linter * test linter error catch * add linter errors annotation matcher * revert linter error test * nits: add Release Workflows name --- .github/workflows/build-preview.yaml | 132 --------------------------- .github/workflows/build.yaml | 49 ++++++++++ .github/workflows/lint-ts.yaml | 38 ++++++++ .github/workflows/release.yaml | 31 +++++++ 4 files changed, 118 insertions(+), 132 deletions(-) delete mode 100644 .github/workflows/build-preview.yaml create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/lint-ts.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/build-preview.yaml b/.github/workflows/build-preview.yaml deleted file mode 100644 index adaa53f..0000000 --- a/.github/workflows/build-preview.yaml +++ /dev/null @@ -1,132 +0,0 @@ -name: Build Preview - -on: - pull_request: - push: - branches: - - main - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }} - cancel-in-progress: true - -jobs: - build: - name: Build - runs-on: namespace-profile-default-cached - steps: - - name: Checkout Cardinal Editor - uses: actions/checkout@v4 - - - uses: pnpm/action-setup@v3 - with: - version: 8 - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - uses: actions/cache@v4 - name: Setup pnpm cache - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm install - - - name: Build - run: pnpm build - - - name: Upload Build to GitHub Artifact - uses: actions/upload-artifact@v4 - with: - name: cardinal-editor-build-${{ github.run_id }} - path: ./dist - - deploy: - name: Deploy - needs: build - runs-on: namespace-profile-default-cached - outputs: - vercel_inspect_url: ${{ steps.deploy.outputs.inspect_url }} - vercel_preview_url: ${{ steps.deploy.outputs.preview_url }} - vercel_environment: ${{ steps.deploy.outputs.environment }} - steps: - - name: Download Artifact From GitHub - uses: actions/download-artifact@v4 - with: - name: cardinal-editor-build-${{ github.run_id }} - path: ./dist - - - name: Install Vercel CLI - run: npm install --global vercel@latest - - - name: Fix File Ownership - run: | - sudo chown -R $USER ./dist - - - name: Set Local Shell Environment Variable - run: | - echo "VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}" >> $GITHUB_ENV - echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}" >> $GITHUB_ENV - - - name: Pull Vercel Environment Information - working-directory: ./dist - run: | - export VERCEL_ENV="preview" - [[ "${{ github.ref }}" == "refs/heads/main" ]] && export VERCEL_ENV="production" - - vercel pull --yes --environment=$VERCEL_ENV --token=${{ secrets.VERCEL_TOKEN }} - - - name: Build - working-directory: ./dist - run: | - [[ "${{ github.ref }}" == "refs/heads/main" ]] && export ARGS="--prod" - vercel build --token=${{ secrets.VERCEL_TOKEN }} $ARGS - - - name: Deploy - id: deploy - working-directory: ./dist - run: | - export VERCEL_ENV="preview" - export SLACK_ENV="Development" - if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then - export ARGS="--prod" - export VERCEL_ENV="production" - export SLACK_ENV="Production" - fi - - vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} $ARGS 2>&1 | tee output.txt - - ## Get Vercel deploy URL and store as job steps output - echo "inspect_url=$(cat output.txt | grep Inspect | grep -Eo "https://[a-zA-Z0-9./?=_%:-]*")" >> "$GITHUB_OUTPUT" - echo "preview_url=$(cat output.txt | grep -i $VERCEL_ENV | grep -Eo "https://[a-zA-Z0-9./?=_%:-]*")" >> "$GITHUB_OUTPUT" - echo "environment=$SLACK_ENV" >> "$GITHUB_OUTPUT" - - - name: Post Vercel Preview URL to PR Comment - if: ${{ github.event_name == 'pull_request' }} - uses: thollander/actions-comment-pull-request@v2 - with: - comment_tag: vercel_deploy - message: | - ### Build deployed to Vercel - ___ - :mag: Inspect: ${{ steps.deploy.outputs.inspect_url }} - :globe_with_meridians: Build: ${{ steps.deploy.outputs.preview_url }} - - slack_notification: - name: Slack Notification - uses: Argus-Labs/devops-infra/.github/workflows/slack-build-notification.yml@debug - needs: deploy - with: - client_name: Cardinal Editor - build_preview_url: ${{ needs.deploy.outputs.vercel_preview_url }} - build_inspect_url: ${{ needs.deploy.outputs.vercel_inspect_url }} - build_environment: ${{ needs.deploy.outputs.vercel_environment }} - slack_channel_id: ${{ vars.SLACK_CHANNEL_ID }} - secrets: - slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..a41e989 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,49 @@ +name: Build + +on: + pull_request: + push: + branches: + - main + workflow_call: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout Cardinal Editor + uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + with: + version: 8 + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + - name: Build + run: pnpm build + - name: Archive Release + uses: thedoctor0/zip-release@0.7.6 + with: + type: 'zip' + filename: 'cardinal-editor.zip' + path: ./dist/ + - name: Upload Build to Github artifact + uses: actions/upload-artifact@v4 + with: + name: cardinal-editor + path: cardinal-editor.zip diff --git a/.github/workflows/lint-ts.yaml b/.github/workflows/lint-ts.yaml new file mode 100644 index 0000000..82913a2 --- /dev/null +++ b/.github/workflows/lint-ts.yaml @@ -0,0 +1,38 @@ +name: Lint + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint-ts: + name: Typescript + runs-on: ubuntu-latest + steps: + - name: Checkout Cardinal Editor + uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + with: + version: 8 + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + - name: Lint + run: pnpm lint diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..96e66a9 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,31 @@ +name: Release + +on: + release: + types: [created] + +permissions: + contents: write + +jobs: + build: + name: Build + uses: ./.github/workflows/build.yaml + + release: + name: Release Build Package + runs-on: ubuntu-latest + needs: build + steps: + - name: Download Cardinal-Editor build + uses: actions/download-artifact@v4 + - name: Rename build with tag + run: | + ls -R + mv cardinal-editor/cardinal-editor.zip cardinal-editor-${{ github.event.release.tag_name }}.zip + - name: Publish Build to corresponding Github Release + uses: skx/github-action-publish-binaries@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: 'cardinal-editor-${{ github.event.release.tag_name }}.zip'