From c5a025744da38bde5551b1fe20d3da8d04861750 Mon Sep 17 00:00:00 2001 From: MacRat Date: Mon, 1 Jan 2024 21:44:34 +0900 Subject: [PATCH] chore(CI): separate deploy workflows --- .github/workflows/build.yml | 10 ++++ .github/workflows/deploy.yml | 85 -------------------------------- .github/workflows/preview.yml | 37 ++++++++++++++ .github/workflows/production.yml | 37 ++++++++++++++ 4 files changed, 84 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/preview.yml create mode 100644 .github/workflows/production.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3fb955a..aca1dd21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,16 @@ on: push: jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.21.x + - uses: actions/checkout@v3 + - run: cd builder && go test -race ./... + build: name: Build runs-on: ubuntu-latest diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index f6ac59ae..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: deploy - -on: - push: - -env: - VERCEL_ORG_ID: ${{secrets.VERCEL_ORG_ID}} - VERCEL_PROJECT_ID: ${{secrets.VERCEL_PROJECT_ID}} - -jobs: - test: - name: Test - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v3 - with: - go-version: 1.21.x - - uses: actions/checkout@v3 - - run: cd builder && go test -race ./... - - preview: - name: Preview Deploy - runs-on: ubuntu-latest - needs: [test] - if: ${{github.ref != 'refs/heads/master' && github.ref != 'refs/hedas/photos'}} - environment: - name: preview - url: ${{steps.deploy.outputs.url}} - steps: - - uses: actions/setup-go@v3 - with: - go-version: 1.21.x - - name: Checkout base branch - uses: actions/checkout@v3 - - name: Checkout photos branch - uses: actions/checkout@v3 - with: - ref: photos - path: pages/photos - - name: Build pages - run: make build - - name: Instal Vercel CLI - run: npm install --global vercel@latest - - name: Pull Vercel Environment Information - run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} - - name: Build Project Artifacts - run: vercel build --token=${{ secrets.VERCEL_TOKEN }} - - name: Deploy Project Artifacts to Vercel - id: deploy - run: | - echo -n "url=" >> $GITHUB_OUTPUT - vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} >> $GITHUB_OUTPUT - - production: - name: Production Deploy - runs-on: ubuntu-latest - needs: [test] - if: ${{github.ref == 'refs/heads/master' || github.ref == 'refs/hedas/photos'}} - environment: - name: production - url: ${{steps.deploy.outputs.url}} - steps: - - uses: actions/setup-go@v3 - with: - go-version: 1.21.x - - name: Checkout base branch - uses: actions/checkout@v3 - - name: Checkout photos branch - uses: actions/checkout@v3 - with: - ref: photos - path: pages/photos - - name: Build pages - run: make build - - name: Instal Vercel CLI - run: npm install --global vercel@latest - - name: Pull Vercel Environment Information - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} - - name: Build Project Artifacts - run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} - - name: Deploy Project Artifacts to Vercel - id: deploy - run: | - echo -n "url=" >> $GITHUB_OUTPUT - vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }} >> $GITHUB_OUTPUT diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 00000000..b70924c8 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,37 @@ +name: preview + +on: + workflow_run: + workflows: [build] + types: [completed] + branches-ignore: + - master + - photos + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + preview: + name: Deploy + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + environment: + name: preview + url: ${{ steps.deploy.outputs.url }} + steps: + - name: Instal Vercel CLI + run: npm install --global vercel@latest + + - name: Load artifact + uses: actions/download-artifact@v4 + with: dist + + - name: Pull Vercel environment information + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy to Vercel + id: deploy + run: | + echo -n "url=" >> $GITHUB_OUTPUT + vercel deploy --token=${{ secrets.VERCEL_TOKEN }} >> $GITHUB_OUTPUT diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml new file mode 100644 index 00000000..e2e6a4a4 --- /dev/null +++ b/.github/workflows/production.yml @@ -0,0 +1,37 @@ +name: production + +on: + workflow_run: + workflows: [build] + types: [completed] + branches: + - master + - photos + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + production: + name: Deploy + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + environment: + name: production + url: ${{ steps.deploy.outputs.url }} + steps: + - name: Instal Vercel CLI + run: npm install --global vercel@latest + + - name: Load artifact + uses: actions/download-artifact@v4 + with: dist + + - name: Pull Vercel environment information + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy to Vercel + id: deploy + run: | + echo -n "url=" >> $GITHUB_OUTPUT + vercel deploy --token=${{ secrets.VERCEL_TOKEN }} --prod >> $GITHUB_OUTPUT