diff --git a/.github/workflows/_deploy-reusable.yaml b/.github/workflows/_deploy-reusable.yaml new file mode 100644 index 00000000..e9700499 --- /dev/null +++ b/.github/workflows/_deploy-reusable.yaml @@ -0,0 +1,96 @@ +name: Reusable Deployment Workflow + +on: + workflow_call: + inputs: + is_prod: + required: true + type: boolean + skip_db: + required: true + type: boolean + secrets: + DB_URL: + required: true + DB_AUTH_TOKEN: + required: true + DB_HTTP_URL: + required: true + DB_AUTH_TOKEN_HTTP: + required: true + INTERNAL_API_KEY: + required: true + NETLIFY_SITE_ID: + required: true + NETLIFY_ACCESS_TOKEN: + required: true + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Install pnpm + uses: pnpm/action-setup@v5 + with: + version: 10 + + - name: Use Node.js + uses: actions/setup-node@v5 + with: + node-version: 24.14.0 + cache: 'pnpm' + + - name: Install Dependencies + run: pnpm i + + - name: Generate SvelteKit config + run: pnpm svelte-kit sync + + - name: Update database + if: ${{ !inputs.skip_db }} + env: + DB_URL: ${{ secrets.DB_URL }} + DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} + run: pnpm db:update + + - name: Build app + env: + DB_URL: ${{ secrets.DB_URL }} + DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} + DB_HTTP_URL: ${{ secrets.DB_HTTP_URL }} + DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_AUTH_TOKEN_HTTP }} + INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} + run: pnpm build + + - name: Get latest commit message + id: msg + run: | + echo "COMMIT_MESSAGE<> $GITHUB_ENV + git log -1 --pretty=%B >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Deploy to Netlify + run: | + pnpm --package=netlify-cli dlx netlify deploy --no-build \ + --dir build \ + --site ${{ secrets.NETLIFY_SITE_ID }} \ + --auth ${{ secrets.NETLIFY_ACCESS_TOKEN }} \ + --message "${{ env.COMMIT_MESSAGE }}" \ + ${{ inputs.is_prod && '--prod' || '' }} + + - name: Create deployment tag + if: ${{ success() && inputs.is_prod }} + run: | + TIMESTAMP=$(date -u +'%Y-%m-%d_%H-%M-%S') + TAG="deploy-${TIMESTAMP}-${GITHUB_SHA::7}" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "$TAG" -m "Deploy $TAG" + git push --no-verify origin "$TAG" diff --git a/.github/workflows/deploy-preview-skip-db.yaml b/.github/workflows/deploy-preview-skip-db.yaml new file mode 100644 index 00000000..910ea803 --- /dev/null +++ b/.github/workflows/deploy-preview-skip-db.yaml @@ -0,0 +1,20 @@ +name: preview deployment (without db update) +on: + workflow_dispatch: + +jobs: + call-deploy: + uses: ./.github/workflows/_deploy-reusable.yaml + permissions: + contents: write + with: + is_prod: false + skip_db: true + secrets: + DB_URL: ${{ secrets.DB_PREVIEW_URL }} + DB_AUTH_TOKEN: ${{ secrets.DB_PREVIEW_AUTH_TOKEN }} + DB_HTTP_URL: ${{ secrets.DB_PREVIEW_HTTP_URL }} + DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_PREVIEW_AUTH_TOKEN_HTTP }} + INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_ACCESS_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }} diff --git a/.github/workflows/deploy-preview.yaml b/.github/workflows/deploy-preview.yaml index 523e625a..66e2cd41 100644 --- a/.github/workflows/deploy-preview.yaml +++ b/.github/workflows/deploy-preview.yaml @@ -1,52 +1,20 @@ name: preview deployment - on: workflow_dispatch: jobs: - build-and-deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v5 - - - name: Install pnpm - uses: pnpm/action-setup@v5 - with: - version: 10 - - - name: Use Node.js - uses: actions/setup-node@v5 - with: - node-version: 24.14.0 - cache: 'pnpm' - - - name: Install Dependencies - run: pnpm i - - - name: Generate SvelteKit config - run: pnpm svelte-kit sync - - - name: Update database - env: - DB_URL: ${{ secrets.DB_PREVIEW_URL }} - DB_AUTH_TOKEN: ${{ secrets.DB_PREVIEW_AUTH_TOKEN }} - run: pnpm db:update - - - name: Build app - env: - DB_URL: ${{ secrets.DB_PREVIEW_URL }} - DB_AUTH_TOKEN: ${{ secrets.DB_PREVIEW_AUTH_TOKEN }} - DB_HTTP_URL: ${{ secrets.DB_PREVIEW_HTTP_URL }} - DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_PREVIEW_AUTH_TOKEN_HTTP }} - INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} - run: pnpm build - - - name: Deploy to Netlify - Preview - run: | - pnpm --package=netlify-cli dlx netlify deploy --no-build \ - --dir build \ - --site ${{ secrets.NETLIFY_SITE_ID }} \ - --auth ${{ secrets.NETLIFY_ACCESS_TOKEN }} \ - --message "${{ github.event.head_commit.message }}" + call-deploy: + uses: ./.github/workflows/_deploy-reusable.yaml + permissions: + contents: write + with: + is_prod: false + skip_db: false + secrets: + DB_URL: ${{ secrets.DB_PREVIEW_URL }} + DB_AUTH_TOKEN: ${{ secrets.DB_PREVIEW_AUTH_TOKEN }} + DB_HTTP_URL: ${{ secrets.DB_PREVIEW_HTTP_URL }} + DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_PREVIEW_AUTH_TOKEN_HTTP }} + INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_ACCESS_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }} diff --git a/.github/workflows/deploy-prod-skip-db.yaml b/.github/workflows/deploy-prod-skip-db.yaml index dda69c24..00ebb61d 100644 --- a/.github/workflows/deploy-prod-skip-db.yaml +++ b/.github/workflows/deploy-prod-skip-db.yaml @@ -1,68 +1,20 @@ name: production deployment (without db update) - on: workflow_dispatch: -permissions: - contents: write - jobs: - build-and-deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - fetch-depth: 0 - - - name: Install pnpm - uses: pnpm/action-setup@v5 - with: - version: 10 - - - name: Use Node.js - uses: actions/setup-node@v5 - with: - node-version: 24.14.0 - cache: 'pnpm' - - - name: Install Dependencies - run: pnpm i - - - name: Generate SvelteKit config - run: pnpm svelte-kit sync - - - name: Build app - env: - DB_URL: ${{ secrets.DB_URL }} - DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} - DB_HTTP_URL: ${{ secrets.DB_HTTP_URL }} - DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_AUTH_TOKEN_HTTP }} - INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} - run: pnpm build - - - name: Get latest commit message - run: | - echo "COMMIT_MESSAGE<> $GITHUB_ENV - git log -1 --pretty=%B >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Deploy to Netlify - Production - run: | - pnpm --package=netlify-cli dlx netlify deploy --no-build \ - --dir build \ - --site ${{ secrets.NETLIFY_SITE_ID }} \ - --auth ${{ secrets.NETLIFY_ACCESS_TOKEN }} \ - --message "${{ env.COMMIT_MESSAGE }}" \ - --prod - - - name: Create deployment tag - if: success() - run: | - TIMESTAMP=$(date -u +'%Y-%m-%d_%H-%M-%S') - TAG="deploy-${TIMESTAMP}-${GITHUB_SHA::7}" - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git tag -a "$TAG" -m "Deploy $TAG" - git push --no-verify origin "$TAG" + call-deploy: + uses: ./.github/workflows/_deploy-reusable.yaml + permissions: + contents: write + with: + is_prod: true + skip_db: true + secrets: + DB_URL: ${{ secrets.DB_URL }} + DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} + DB_HTTP_URL: ${{ secrets.DB_HTTP_URL }} + DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_AUTH_TOKEN_HTTP }} + INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_ACCESS_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }} diff --git a/.github/workflows/deploy-prod.yaml b/.github/workflows/deploy-prod.yaml index 4656c00f..255907c1 100644 --- a/.github/workflows/deploy-prod.yaml +++ b/.github/workflows/deploy-prod.yaml @@ -1,74 +1,20 @@ name: production deployment - on: workflow_dispatch: -permissions: - contents: write - jobs: - build-and-deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - fetch-depth: 0 - - - name: Install pnpm - uses: pnpm/action-setup@v5 - with: - version: 10 - - - name: Use Node.js - uses: actions/setup-node@v5 - with: - node-version: 24.14.0 - cache: 'pnpm' - - - name: Install Dependencies - run: pnpm i - - - name: Generate SvelteKit config - run: pnpm svelte-kit sync - - - name: Update database - env: - DB_URL: ${{ secrets.DB_URL }} - DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} - run: pnpm db:update - - - name: Build app - env: - DB_URL: ${{ secrets.DB_URL }} - DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} - DB_HTTP_URL: ${{ secrets.DB_HTTP_URL }} - DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_AUTH_TOKEN_HTTP }} - INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} - run: pnpm build - - - name: Get latest commit message - run: | - echo "COMMIT_MESSAGE<> $GITHUB_ENV - git log -1 --pretty=%B >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Deploy to Netlify - Production - run: | - pnpm --package=netlify-cli dlx netlify deploy --no-build \ - --dir build \ - --site ${{ secrets.NETLIFY_SITE_ID }} \ - --auth ${{ secrets.NETLIFY_ACCESS_TOKEN }} \ - --message "${{ env.COMMIT_MESSAGE }}" \ - --prod - - - name: Create deployment tag - if: success() - run: | - TIMESTAMP=$(date -u +'%Y-%m-%d_%H-%M-%S') - TAG="deploy-${TIMESTAMP}-${GITHUB_SHA::7}" - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git tag -a "$TAG" -m "Deploy $TAG" - git push --no-verify origin "$TAG" + call-deploy: + uses: ./.github/workflows/_deploy-reusable.yaml + permissions: + contents: write + with: + is_prod: true + skip_db: false + secrets: + DB_URL: ${{ secrets.DB_URL }} + DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }} + DB_HTTP_URL: ${{ secrets.DB_HTTP_URL }} + DB_AUTH_TOKEN_HTTP: ${{ secrets.DB_AUTH_TOKEN_HTTP }} + INTERNAL_API_KEY: ${{ secrets.INTERNAL_API_KEY }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_ACCESS_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }}