Skip to content

Merge pull request #1284 from rharkor/dev #610

Merge pull request #1284 from rharkor/dev

Merge pull request #1284 from rharkor/dev #610

Workflow file for this run

name: Deployment
on:
push:
branches:
- dev
- rec
- main
workflow_dispatch:
inputs:
FORCE_APP_DEPLOY:
description: "Force deploy app"
required: false
default: "false"
FORCE_DOCS_DEPLOY:
description: "Force deploy docs"
required: false
default: "false"
FORCE_CRON_DEPLOY:
description: "Force deploy cron"
required: false
default: "false"
FORCE_LANDING_DEPLOY:
description: "Force deploy landing"
required: false
default: "false"
env:
# push => github.event.before
# pull_request => github.event.pull_request.base.sha
# workflow_dispatch => HEAD^
TURBO_RUN_FILTER: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event_name == 'push' && github.event.before || 'HEAD^' }}
jobs:
checks:
name: Build
runs-on: ubuntu-latest
outputs:
changed-app: ${{ steps.changed-app.outputs.result }}
changed-docs: ${{ steps.changed-docs.outputs.result }}
changed-cron: ${{ steps.changed-cron.outputs.result }}
changed-landing: ${{ steps.changed-landing.outputs.result }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"
- name: Changeset
id: changeset
# 1. We need the 'output' of a turbo dry-run to get a json with all affected packages of these run.
# 2. The multi line json string is transformed to a single line string.
# 3. The single line json string is set to an 'output' (or result) of this step.
run: |
npx -y turbo build --filter="...[$TURBO_RUN_FILTER]" --dry-run=json > $GITHUB_WORKSPACE/result.json 2> error.log
content=$(cat $GITHUB_WORKSPACE/result.json)
if [ $? -ne 0 ]; then
echo 'result<<EOF' >> $GITHUB_OUTPUT
cat error.log >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo 'result<<EOF' >> $GITHUB_OUTPUT
echo "$content" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
- name: Upload Result as Artifact
uses: actions/upload-artifact@v4
with:
name: changeset-result
path: ${{ github.workspace }}/result.json
- name: Changed app?
id: changed-app
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/app') || github.event.inputs.FORCE_APP_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
- name: Changed docs?
id: changed-docs
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/docs') || github.event.inputs.FORCE_DOCS_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
- name: Changed cron?
id: changed-cron
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/cron') || github.event.inputs.FORCE_CRON_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
- name: Changed landing?
id: changed-landing
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/landing') || github.event.inputs.FORCE_LANDING_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
deploy_app:
name: Deploy app
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-app == 'true' }}
steps:
- name: Deploy app
run: |
echo "### Deploying app πŸš€" >> $GITHUB_STEP_SUMMARY
echo "Found changes in app compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY
deploy_docs:
name: Deploy docs
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-docs == 'true' }}
steps:
- name: Deploy docs
run: |
echo "### Deploying docs πŸš€" >> $GITHUB_STEP_SUMMARY
echo "Found changes in docs compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY
deploy_cron:
name: Deploy cron
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-cron == 'true' }}
steps:
- name: Deploy cron
run: |
echo "### Deploying cron πŸš€" >> $GITHUB_STEP_SUMMARY
echo "Found changes in cron compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY
deploy_landing:
name: Deploy landing
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-landing == 'true' }}
steps:
- name: Deploy landing
run: |
echo "### Deploying landing πŸš€" >> $GITHUB_STEP_SUMMARY
echo "Found changes in landing compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY