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
97 changes: 80 additions & 17 deletions .github/workflows/ci-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:
contents: read

concurrency:
group: deploy-catalog
group: Deploy Catalog
cancel-in-progress: false

jobs:
Expand All @@ -19,15 +19,21 @@ jobs:
env:
NODE_VERSION: "20.x"
AWS_REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET: ${{ vars.S3_BUCKET_HOST }}
S3_BUCKET: ${{ vars.S3_BUCKET_HOST }}
VITE_HOST: ${{ vars.VITE_HOST }}
APP_PREFIX: catalog
CF_DISTRIBUTION_ID: ${{ vars.CLOUDFRONT_DISTRIBUTION_ID_HOST }}
COLLECTOR_API: ${{ secrets.COLLECTOR_API }}
ARCHITECTURE_TYPE: "microfrontend"
APP_CONTEXT: "catalog"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Capture start ci
run: echo "CI_START_TS=$(date -u +%s)" >> "$GITHUB_ENV"

- name: Setup Node
uses: actions/setup-node@v4
with:
Expand All @@ -37,6 +43,22 @@ jobs:
- name: Install
run: npm ci

- name: Unit tests
run: |
npx vitest run --reporter=dot --reporter=json --outputFile=test-report.json --coverage \
|| { echo "VITEST_FAILED=1" >> "$GITHUB_ENV"; exit 1; }
continue-on-error: true

- name: Flag test status
run: |
if [ -f test-report.json ]; then
echo "TEST_REPORT_PATH=test-report.json" >> "$GITHUB_ENV"
fi
if [ -f coverage/coverage-summary.json ]; then
echo "COVERAGE_SUMMARY_PATH=coverage/coverage-summary.json" >> "$GITHUB_ENV"
fi
echo "VITEST_FAILED=${VITEST_FAILED:-0}" >> "$GITHUB_ENV"

- name: Build
run: npm run build

Expand All @@ -49,21 +71,62 @@ jobs:

- name: Upload to S3
run: |
set -euo pipefail
aws s3 sync ./dist "s3://${S3_BUCKET}/${APP_PREFIX}/" \
--delete --only-show-errors \
--exclude "index.html" \
--exclude "remoteEntry.js" \
--cache-control "public,max-age=31536000,immutable"
set -euo pipefail
aws s3 sync ./dist "s3://${S3_BUCKET}/${APP_PREFIX}/" \
--delete --only-show-errors \
--exclude "index.html" \
--exclude "remoteEntry.js" \
--cache-control "public,max-age=31536000,immutable"

- name: Publish Remote Entry
run: |
set -euo pipefail
if [ -f "./dist/remoteEntry.js" ]; then
echo "remoteEntry.js publish remote entry"
aws s3 cp "./dist/remoteEntry.js" "s3://${S3_BUCKET}/${APP_PREFIX}/remoteEntry.js" \
--cache-control "public,max-age=300"
aws cloudfront create-invalidation \
--distribution-id "${CF_DISTRIBUTION_ID}" \
--paths "/${APP_PREFIX}/remoteEntry.js"
fi
set -euo pipefail
if [ -f "./dist/remoteEntry.js" ]; then
echo "remoteEntry.js publish remote entry"
aws s3 cp "./dist/remoteEntry.js" "s3://${S3_BUCKET}/${APP_PREFIX}/remoteEntry.js" \
--cache-control "public,max-age=300"
aws cloudfront create-invalidation \
--distribution-id "${CF_DISTRIBUTION_ID}" \
--paths "/${APP_PREFIX}/remoteEntry.js"
fi

- name: compute bundle metrics
run: |
TOTAL=$(find dist -type f -printf '%s\n' | awk '{s+=$1} END {print s+0}')
echo "{\"totalBytes\":$TOTAL}" > bundle-metrics.json

- name: expose git facts to env
shell: bash
run: |
set -o errexit -o pipefail

COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
GIT_AUTHOR_NAME="$(git log -1 --pretty=%an)"
GIT_AUTHOR_EMAIL="$(git log -1 --pretty=%ae)"
PR_NUMBER="${{ github.event.pull_request.number || '' }}"
VERSION="$(node -e "console.log(require('./package.json').version)")"

{
echo 'COMMIT_MESSAGE<<EOF'
printf '%s\n' "$COMMIT_MESSAGE"
echo 'EOF'
echo "GIT_AUTHOR_NAME=$GIT_AUTHOR_NAME"
echo "GIT_AUTHOR_EMAIL=$GIT_AUTHOR_EMAIL"
echo "PR_NUMBER=$PR_NUMBER"
echo "VERSION=$VERSION"
echo "CC_TYPE=$CC_TYPE"
echo "CC_SCOPE=$CC_SCOPE"
} >> "$GITHUB_ENV"

- name: Build metrics JSON
run: node scripts/collect-ci.js
env:
BUNDLE_METRICS_PATH: bundle-metrics.json
COVERAGE_SUMMARY_PATH: ${{ env.COVERAGE_SUMMARY_PATH }}
TEST_REPORT_PATH: ${{ env.TEST_REPORT_PATH }}

- name: Collect data
run: |
curl -sS -X POST -H "Content-Type: application/json" \
--data @metrics.json \
"$COLLECTOR_API"
73 changes: 61 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ name: CI

on:
push:
branches: ["**"]
pull_request:
types: [opened, synchronize, reopened]
branches-ignore: [main]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
quality-and-tests:
name: Lint - Unit - Integration - Typecheck - Build
name: Commit Check
runs-on: ubuntu-latest

defaults:
Expand All @@ -23,11 +21,17 @@ jobs:
NODE_VERSION: "20.x"
VITE_HOST: ${{ vars.VITE_HOST }}
CI: "true"
COLLECTOR_API: ${{ secrets.COLLECTOR_API }}
ARCHITECTURE_TYPE: "microfrontend"
APP_CONTEXT: "catalog"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Capture start ci
run: echo "CI_START_TS=$(date -u +%s)" >> "$GITHUB_ENV"

- name: Setup Node
uses: actions/setup-node@v4
with:
Expand All @@ -37,17 +41,62 @@ jobs:
- name: Install
run: npm ci

- name: Unit tests
run: |
npx vitest run --reporter=dot --reporter=json --outputFile=test-report.json --coverage \
|| { echo "VITEST_FAILED=1" >> "$GITHUB_ENV"; exit 1; }
continue-on-error: true

- name: Flag test status
run: |
if [ -f test-report.json ]; then
echo "TEST_REPORT_PATH=test-report.json" >> "$GITHUB_ENV"
fi
if [ -f coverage/coverage-summary.json ]; then
echo "COVERAGE_SUMMARY_PATH=coverage/coverage-summary.json" >> "$GITHUB_ENV"
fi
echo "VITEST_FAILED=${VITEST_FAILED:-0}" >> "$GITHUB_ENV"

- name: Build
run: npm run build

# - name: Lint
# run: npm run lint --if-present
- name: compute bundle metrics
run: |
TOTAL=$(find dist -type f -printf '%s\n' | awk '{s+=$1} END {print s+0}')
echo "{\"totalBytes\":$TOTAL}" > bundle-metrics.json

- name: expose git facts to env
shell: bash
run: |
set -o errexit -o pipefail

COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
GIT_AUTHOR_NAME="$(git log -1 --pretty=%an)"
GIT_AUTHOR_EMAIL="$(git log -1 --pretty=%ae)"
PR_NUMBER="${{ github.event.pull_request.number || '' }}"
VERSION="$(node -e "console.log(require('./package.json').version)")"

# - name: Typecheck
# run: npm run typecheck --if-present
{
echo 'COMMIT_MESSAGE<<EOF'
printf '%s\n' "$COMMIT_MESSAGE"
echo 'EOF'
echo "GIT_AUTHOR_NAME=$GIT_AUTHOR_NAME"
echo "GIT_AUTHOR_EMAIL=$GIT_AUTHOR_EMAIL"
echo "PR_NUMBER=$PR_NUMBER"
echo "VERSION=$VERSION"
echo "CC_TYPE=$CC_TYPE"
echo "CC_SCOPE=$CC_SCOPE"
} >> "$GITHUB_ENV"

# - name: Unit tests
# run: npm run test:unit --if-present -- --reporter=dot
- name: Build metrics JSON
run: node scripts/collect-ci.js
env:
BUNDLE_METRICS_PATH: bundle-metrics.json
COVERAGE_SUMMARY_PATH: ${{ env.COVERAGE_SUMMARY_PATH }}
TEST_REPORT_PATH: ${{ env.TEST_REPORT_PATH }}

# - name: E2E tests
# run: npm run test:integration --if-present
- name: Collect data
run: |
curl -sS -X POST -H "Content-Type: application/json" \
--data @metrics.json \
"$COLLECTOR_API"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ coverage
*.sln
*.sw?

.__mf__temp
.__mf__temp
.env*
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no -- commitlint --edit "$1"
Empty file added .husky/pre-commit
Empty file.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
Loading