Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Builds the application and its changelog, and uploads them as the
# `build-output` artifact. BUILD (develop) and RELEASE (PlaceOS releases) call
# this workflow, then publish the artifact to a build/* branch.
name: BUILD APP

on:
workflow_call:
inputs:
ref:
description: 'Commit to build. Empty: the commit that started the run'
type: string
default: ''
configuration:
description: 'Angular build configuration: development or production'
type: string
required: true
tag:
description: 'Release tag to add to the commit before the build. The version info shows it'
type: string
default: ''

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}

# The changelog needs the history and tags of this commit only.
# fetch-depth: 0 also downloads the build/* deploy branches (about
# 560 MB against 30 MB).
- name: Fetch history and tags
env:
REF: ${{ inputs.ref || github.ref }}
run: git fetch --unshallow --tags origin "$REF"

# Local only. config/version.js (git describe) and git-cliff read
# it. RELEASE pushes the tag after the deploy. --force: a retry of
# a release fetches the tag that the first run pushed.
- name: Tag the release
if: inputs.tag != ''
env:
TAG: ${{ inputs.tag }}
run: git tag --force "$TAG"

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.11'

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Setup version
run: bun run postinstall

- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff@2.13.1

- name: Initialise Pipeline Chat Status
uses: fjogeleit/http-request-action@master
continue-on-error: true
with:
url: ${{ secrets.STATUS_URL }}
data: '{ "chat_url": "${{ secrets.CHAT_URL }}", "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "backoffice", "branch": "${{ github.ref }}", "status": "processing", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'

# Do not restore an Nx cache for this build. Nx does not hash the
# gitignored src/env/version.ts, so a cached build could deploy
# the version info of an earlier commit.
# git-cliff runs alongside the build; `wait` fails the step if it fails.
# Do not set GITHUB_REPO. cliff.toml uses no GitHub metadata, and
# the unauthenticated metadata requests hit the API rate limit.
- name: Build application and changelog
env:
CONFIGURATION: ${{ inputs.configuration }}
run: |
git-cliff --config cliff.toml --output "${RUNNER_TEMP}/CHANGELOG.md" &
cliff_pid=$!
bun run build -- --verbose --configuration="$CONFIGURATION"
wait "$cliff_pid"

- name: Add application changelog to build
run: cp "${RUNNER_TEMP}/CHANGELOG.md" dist/backoffice/browser/CHANGELOG.md

# Upload source maps so Sentry shows the original code. Skipped
# until the SENTRY_* secrets are set. Debug IDs change the scripts,
# so the service worker hashes are updated after. Development
# builds have no service worker.
# The release name must match SENTRY_RELEASE in src/app/common/sentry.ts.
- name: Upload source maps to Sentry
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
run: |
if [ -z "$SENTRY_AUTH_TOKEN" ] || [ -z "$SENTRY_ORG" ] || [ -z "$SENTRY_PROJECT" ]; then
echo "SENTRY_AUTH_TOKEN, SENTRY_ORG or SENTRY_PROJECT is not set. Skipping upload."
exit 0
fi
release=$(bun -e "import { VERSION } from './src/env/version.ts'; console.log('backoffice@' + VERSION.hash)")
bunx sentry-cli sourcemaps inject dist/backoffice/browser
if [ -f dist/backoffice/browser/ngsw.json ]; then
bun config/ngsw-rehash.js dist/backoffice/browser
fi
bunx sentry-cli sourcemaps upload --release="$release" dist/backoffice/browser

# Production builds make hidden source maps for Sentry only
- name: Remove hidden source maps
if: inputs.configuration != 'development'
run: find dist/backoffice/browser -name '*.map' -delete

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/backoffice/browser
retention-days: 1
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
171 changes: 15 additions & 156 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,133 +1,30 @@
# Builds develop and publishes it to build/dev. PlaceOS releases publish to
# build/prod through RELEASE (release.yml). See docs/releases.md.
name: BUILD

on:
push:
branches: [develop, release/**, rc/**, release]
branches: [develop]

permissions:
contents: read

jobs:
# Run tests for all branches (runs in parallel with build)
# Tests run in parallel with the build. The dev deploy does not wait for them.
test:
uses: ./.github/workflows/test.yml

# Build job runs immediately without waiting for tests
build:
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
configuration: ${{ steps.build_ext.outputs.configuration }}
deploy_branch: ${{ steps.build_ext.outputs.deploy_branch }}
is_production: ${{ steps.build_ext.outputs.is_production }}
steps:
- uses: actions/checkout@v6

# The changelog needs the history and tags of this branch only.
# fetch-depth: 0 also downloads the build/* deploy branches (about
# 560 MB against 30 MB).
- name: Fetch branch history and tags
run: git fetch --unshallow --tags origin "$GITHUB_REF"

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.11'

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Setup version
run: bun run postinstall

- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff@2.13.1

- name: Extract branch name
id: branch_name
shell: bash
run: echo "name=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_OUTPUT

- name: Extract build configuration
shell: bash
id: build_ext
run: |
if [[ ${{ steps.branch_name.outputs.name }} == "release" ]] || [[ ${{ steps.branch_name.outputs.name }} == "release"* ]] || [[ ${{ steps.branch_name.outputs.name }} == "main" ]]
then
echo "configuration=production" >> $GITHUB_OUTPUT
echo "deploy_branch=prod" >> $GITHUB_OUTPUT
echo "is_production=true" >> $GITHUB_OUTPUT
elif [[ ${{ steps.branch_name.outputs.name }} == "rc"* ]]
then
echo "configuration=staging" >> $GITHUB_OUTPUT
echo "deploy_branch=uat" >> $GITHUB_OUTPUT
echo "is_production=true" >> $GITHUB_OUTPUT
else
echo "configuration=development" >> $GITHUB_OUTPUT
echo "deploy_branch=dev" >> $GITHUB_OUTPUT
echo "is_production=false" >> $GITHUB_OUTPUT
fi

- name: Initialise Pipeline Chat Status
uses: fjogeleit/http-request-action@master
continue-on-error: true
with:
url: ${{ secrets.STATUS_URL }}
data: '{ "chat_url": "${{ secrets.CHAT_URL }}", "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "backoffice", "branch": "${{ github.ref }}", "status": "processing", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'

# Do not restore an Nx cache for this build. Nx does not hash the
# gitignored src/env/version.ts, so a cached build could deploy
# the version info of an earlier commit.
# git-cliff runs alongside the build; `wait` fails the step if it fails.
# Do not set GITHUB_REPO. cliff.toml uses no GitHub metadata, and
# the unauthenticated metadata requests hit the API rate limit.
- name: Build application and changelog
run: |
git-cliff --config cliff.toml --output "${RUNNER_TEMP}/CHANGELOG.md" &
cliff_pid=$!
bun run build -- --verbose --configuration=${{ steps.build_ext.outputs.configuration }}
wait "$cliff_pid"

- name: Add application changelog to build
run: cp "${RUNNER_TEMP}/CHANGELOG.md" dist/backoffice/browser/CHANGELOG.md

# Upload source maps so Sentry shows the original code. Skipped
# until the SENTRY_* secrets are set. Debug IDs change the scripts,
# so the service worker hashes are updated after. Development
# builds have no service worker.
# The release name must match SENTRY_RELEASE in src/app/common/sentry.ts.
- name: Upload source maps to Sentry
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
run: |
if [ -z "$SENTRY_AUTH_TOKEN" ] || [ -z "$SENTRY_ORG" ] || [ -z "$SENTRY_PROJECT" ]; then
echo "SENTRY_AUTH_TOKEN, SENTRY_ORG or SENTRY_PROJECT is not set. Skipping upload."
exit 0
fi
release=$(bun -e "import { VERSION } from './src/env/version.ts'; console.log('backoffice@' + VERSION.hash)")
bunx sentry-cli sourcemaps inject dist/backoffice/browser
if [ -f dist/backoffice/browser/ngsw.json ]; then
bun config/ngsw-rehash.js dist/backoffice/browser
fi
bunx sentry-cli sourcemaps upload --release="$release" dist/backoffice/browser

# Production builds make hidden source maps for Sentry only
- name: Remove hidden source maps
if: steps.build_ext.outputs.configuration != 'development'
run: find dist/backoffice/browser -name '*.map' -delete

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/backoffice/browser
retention-days: 1
uses: ./.github/workflows/build-app.yml
with:
configuration: development
secrets: inherit

# Deploy dev builds immediately after build (don't wait for tests)
deploy-dev:
needs: [build]
if: needs.build.outputs.is_production == 'false'
# Pushes to build/dev
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
Expand All @@ -149,7 +46,7 @@ jobs:
uses: MrYuion/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: build/${{ needs.build.outputs.deploy_branch }}
BRANCH: build/dev
FOLDER: dist/backoffice/browser
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: 'build(backoffice): [{sha}] CI build'
Expand All @@ -161,41 +58,3 @@ jobs:
url: ${{ secrets.STATUS_URL }}
data: '{ "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "backoffice", "branch": "${{ github.ref }}", "status": "${{ job.status }}", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
if: ${{ always() }}

# Deploy production builds only after tests pass
deploy-production:
needs: [build, test]
if: needs.build.outputs.is_production == 'true'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v6

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: dist/backoffice/browser

# Vercel reads vercel.json from the pushed commit. Build branches
# hold only the built files, so add one that turns off deployments.
- name: Turn off Vercel deployments for the build branch
run: |
echo '{ "git": { "deploymentEnabled": false } }' > dist/backoffice/browser/vercel.json

- name: Deploy the application
uses: MrYuion/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: build/${{ needs.build.outputs.deploy_branch }}
FOLDER: dist/backoffice/browser
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: 'build(backoffice): CI build from {sha}'

- name: Update Pipeline Chat Status
uses: fjogeleit/http-request-action@master
continue-on-error: true
with:
url: ${{ secrets.STATUS_URL }}
data: '{ "name": "${{ github.repository }}", "commit": "${{ github.sha }}", "pipeline_name": "backoffice", "branch": "${{ github.ref }}", "status": "${{ job.status }}", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
if: ${{ always() }}
4 changes: 1 addition & 3 deletions .github/workflows/e2e-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ on:
workflow_dispatch:
push:
branches:
# The branches BUILD deploys from
# The branch BUILD deploys from
- develop
- 'release/**'
- 'rc/**'
# To work on this suite and this workflow
- 'e2e/**'
schedule:
Expand Down
Loading
Loading