diff --git a/.github/actions/artifact-download/action.yaml b/.github/actions/artifact-download/action.yaml
index 727b76f9ea..85db6754bf 100644
--- a/.github/actions/artifact-download/action.yaml
+++ b/.github/actions/artifact-download/action.yaml
@@ -1,14 +1,5 @@
###
#
-# If you need to do some changes in a local-action used in this
-# workflow, make sure you change the action-flag to your working
-# branch-name to get the latest action functionality.
-#
-# Example: swisspost/design-system/.github/actions/setup-environment-pnpm@my-working-branch-name
-#
-# Don't forget to change the action-flag back to 'main',
-# once you have finished your work on the local-action!
-#
# https://docs.github.com/en/actions/creating-actions/about-custom-actions#using-release-management-for-actions
#
###
diff --git a/.github/actions/artifact-upload/action.yaml b/.github/actions/artifact-upload/action.yaml
index 8d4ca1970d..a49be5831e 100644
--- a/.github/actions/artifact-upload/action.yaml
+++ b/.github/actions/artifact-upload/action.yaml
@@ -1,14 +1,5 @@
###
#
-# If you need to do some changes in a local-action used in this
-# workflow, make sure you change the action-flag to your working
-# branch-name to get the latest action functionality.
-#
-# Example: swisspost/design-system/.github/actions/setup-environment-pnpm@my-working-branch-name
-#
-# Don't forget to change the action-flag back to 'main',
-# once you have finished your work on the local-action!
-#
# https://docs.github.com/en/actions/creating-actions/about-custom-actions#using-release-management-for-actions
#
###
diff --git a/.github/actions/deploy-to-netlify/action.yaml b/.github/actions/deploy-to-netlify/action.yaml
index 268bef16cc..95eaea412f 100644
--- a/.github/actions/deploy-to-netlify/action.yaml
+++ b/.github/actions/deploy-to-netlify/action.yaml
@@ -1,17 +1,6 @@
###
#
-# This action needs a proper node and pnpm setup before!
-#
-# If you need to do some changes in a local-action used in this
-# workflow, make sure you change the action-flag to your working
-# branch-name to get the latest action functionality.
-#
-# Example: swisspost/design-system/.github/actions/setup-pnpm@my-working-branch-name
-#
-# Don't forget to change the action-flag back to 'main',
-# once you have finished your work on the local-action!
-#
-# https://docs.github.com/en/actions/creating-actions/about-custom-actions#using-release-management-for-actions
+# DEPRECATED: This Action can be removed, as soon as we remove deploy-demo.yaml
#
###
@@ -47,16 +36,16 @@ runs:
steps:
- name: Install netlify-cli
shell: bash
- run: pnpm i -g netlify-cli@16
+ run: pnpm i -g netlify-cli
- name: Deploy preview environment to netlify
id: netlify_deploy
shell: bash
env:
NETLIFY_AUTH_TOKEN: ${{ inputs.netlify_auth_token }}
+ NETLIFY_SITE_ID: ${{ inputs.netlify_site_id }}
# run command taken from https://gist.github.com/oneohthree/f528c7ae1e701ad990e6, shortened to 28 chars, prepended with build-number
- # edited for netifly v16
run: |
url_alias=`echo "preview-${{ inputs.id }}" | iconv -t ascii//TRANSLIT | sed -E 's/[~\^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+\|-+$//g' | sed -E 's/^-+//g' | sed -E 's/-+$//g' | tr A-Z a-z`
- netlify deploy --alias $url_alias --build false --dir ${{ inputs.folder }} --site ${{ inputs.netlify_site_id }} --filter ${{inputs.package_name}}
echo "url_alias=$url_alias" >> $GITHUB_OUTPUT
+ netlify deploy --filter ${{inputs.package_name}} --build false --dir ${{ inputs.folder }} --alias $url_alias
diff --git a/.github/actions/setup-netlify-cli/action.yaml b/.github/actions/setup-netlify-cli/action.yaml
new file mode 100644
index 0000000000..6e8e3acbec
--- /dev/null
+++ b/.github/actions/setup-netlify-cli/action.yaml
@@ -0,0 +1,15 @@
+###
+#
+# NOTE: We've created this action to ensure, we are using the same Netlify-CLI version everywhere
+#
+###
+
+name: Setup Netlify CLI
+description: Provides node and pnpm in a specific version.
+
+runs:
+ using: composite
+ steps:
+ - name: Install netlify-cli
+ shell: bash
+ run: pnpm i -g netlify-cli@17
diff --git a/.github/actions/setup-pnpm/action.yaml b/.github/actions/setup-pnpm/action.yaml
index 56a6db7d1f..9da5430deb 100644
--- a/.github/actions/setup-pnpm/action.yaml
+++ b/.github/actions/setup-pnpm/action.yaml
@@ -5,15 +5,6 @@
# separate terms of service, privacy policy, and support
# documentation.
#
-# If you need to do some changes in a local-action used in this
-# workflow, make sure you change the action-flag to your working
-# branch-name to get the latest action functionality.
-#
-# Example: swisspost/design-system/.github/actions/setup-pnpm@my-working-branch-name
-#
-# Don't forget to change the action-flag back to 'main',
-# once you have finished your work on the local-action!
-#
# https://docs.github.com/en/actions/creating-actions/about-custom-actions#using-release-management-for-actions
#
# NOTE: pnpm caching support requires pnpm version >= 6.10.0
@@ -26,11 +17,9 @@ description: Provides node and pnpm in a specific version.
inputs:
node_version:
description: Specify the node version to install
- default: 20
type: string
pnpm_version:
description: Specify the pnpm version to install
- default: 9
type: string
use_cache:
description: Specify wether to use the pnpm cache or not
@@ -40,13 +29,38 @@ inputs:
runs:
using: composite
steps:
+ - name: Detect wanted version
+ id: wanted-versions
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs')
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
+
+ return {
+ node: pkg.engines?.node,
+ pnpm: pkg.packageManager
+ }
+
- name: Install pnpm
- uses: pnpm/action-setup@v3
+ uses: pnpm/action-setup@v4
with:
- version: ${{ inputs.pnpm_version }}
+ # If input.pnpm_version is NOT defined,
+ # the action automatically uses the "packageManager" field from the package.json file
+ # If input.pnpm_version is defined, we need to point to another package.json file, without the "packageManager" field,
+ # so we do not end up with a "Multiple versions of pnpm specified" error
+ package_json_file: ${{ inputs.pnpm_version && 'packages/documentation/package.json' || 'package.json' }}
+ version: ${{ inputs.pnpm_version || null }}
- - name: Install node with pnpm cache
+ - name: Install node
uses: actions/setup-node@v4
with:
- node-version: ${{ inputs.node_version }}
+ node-version: ${{ inputs.node_version || fromJSON(steps.wanted-versions.outputs.result).node }}
cache: ${{ inputs.use_cache == 'true' && 'pnpm' || '' }}
+
+ - name: Summary
+ shell: bash
+ run: |
+ echo "Installed versions:"
+ echo "- node: ${{ inputs.node_version || fromJSON(steps.wanted-versions.outputs.result).node }}"
+ echo "- pnpm: ${{ inputs.pnpm_version || fromJSON(steps.wanted-versions.outputs.result).pnpm }}"
diff --git a/.github/workflows/build-demo.yaml b/.github/workflows/build-demo.yaml
index 4247ee01d6..1d8c7b52be 100644
--- a/.github/workflows/build-demo.yaml
+++ b/.github/workflows/build-demo.yaml
@@ -1,13 +1,6 @@
###
#
-# Build the demo app and all dependencies
-#
-# This workflow does not have secrets access
-# when run from a fork. Artifacts are uploaded
-# and used in a subsequent workflow with more
-# privileges which does not run unsafe commands.
-#
-# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
+# DEPRECATED: This Action can be removed as soon as we start working on V2/V9
#
###
@@ -36,7 +29,7 @@ jobs:
access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
- name: Bootstrap & Build Design System
run: |
@@ -44,7 +37,7 @@ jobs:
pnpm --filter design-system-demo... build
- name: Upload build artifacts
- uses: swisspost/design-system/.github/actions/artifact-upload@main
+ uses: ./.github/actions/artifact-upload
with:
name: design-system-demo
folder: packages/demo/dist/demo
diff --git a/.github/workflows/build-documentation.yaml b/.github/workflows/build-documentation.yaml
index 290172590c..bf5507801c 100644
--- a/.github/workflows/build-documentation.yaml
+++ b/.github/workflows/build-documentation.yaml
@@ -19,8 +19,8 @@ on:
jobs:
build:
+ name: Build Documentation
runs-on: ubuntu-latest
-
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -31,7 +31,7 @@ jobs:
access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
- name: Install documentation & dependencies
run: pnpm --filter design-system-documentation... install
diff --git a/.github/workflows/deploy-demo.yaml b/.github/workflows/deploy-demo.yaml
index 6511794b54..2e23a6ee6d 100644
--- a/.github/workflows/deploy-demo.yaml
+++ b/.github/workflows/deploy-demo.yaml
@@ -1,8 +1,6 @@
###
#
-# Deploys a pre-built demo app to netlify
-#
-# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
+# DEPRECATED: This Action can be removed as soon as we start working on V2/V9
#
###
@@ -25,10 +23,10 @@ jobs:
uses: actions/checkout@v4
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
- name: Download build artifacts
- uses: swisspost/design-system/.github/actions/artifact-download@main
+ uses: ./.github/actions/artifact-download
id: build
with:
name: design-system-demo
@@ -37,7 +35,7 @@ jobs:
- run: ls -R
- name: Deploy demo app to netlify
- uses: swisspost/design-system/.github/actions/deploy-to-netlify@main
+ uses: ./.github/actions/deploy-to-netlify
id: deploy
with:
id: ${{ steps.build.outputs.id }}
diff --git a/.github/workflows/deploy-documentation.yaml b/.github/workflows/deploy-documentation.yaml
index 8321fb26ff..d2560daaa9 100644
--- a/.github/workflows/deploy-documentation.yaml
+++ b/.github/workflows/deploy-documentation.yaml
@@ -1,12 +1,4 @@
-###
-#
-# Deploy a pre-built documentation to netilfy
-#
-# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
-#
-###
-
-name: Deploy Documentation Preview to Netlify
+name: Deploy Documentation Preview
on:
workflow_run:
workflows: ['Build Documentation']
@@ -14,15 +6,18 @@ on:
jobs:
deploy:
+ name: Deploy Documentation Preview
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
-
steps:
- name: Checkout
uses: actions/checkout@v4
- - name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ - name: Setup pnpm & node
+ uses: ./.github/actions/setup-pnpm
+
+ - name: Setup netlify-cli
+ uses: ./.github/actions/setup-netlify-cli
- name: Download build artifacts
uses: ./.github/actions/artifact-download
@@ -31,20 +26,41 @@ jobs:
name: design-system-documentation
folder: build-output
- - name: Deploy documentation to netlify
- uses: ./.github/actions/deploy-to-netlify
- id: deploy
+ - name: Get netlify config
+ id: netlify-config
+ uses: actions/github-script@v7
with:
- id: ${{ steps.build.outputs.id }}
- netlify_auth_token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
- netlify_site_id: ${{ secrets.NEXT_NETLIFY_SITE_ID }}
- netlify_site_url: swisspost-design-system-next.netlify.app
- folder: ${{ steps.build.outputs.folder }}
- package_name: '@swisspost/design-system-documentation'
+ script: |
+ const fs = require('fs')
+ return JSON.parse(fs.readFileSync('./packages/documentation/netlify.config.json', 'utf8'))
+
+ - name: Deploy Documentation Preview
+ id: deploy
+ env:
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ NETLIFY_SITE_ID: ${{ fromJSON(steps.netlify-config.outputs.result).siteId }}
+ # run command taken from https://gist.github.com/oneohthree/f528c7ae1e701ad990e6, shortened to 28 chars, prepended with build-number
+ run: |
+ url_alias=`echo "preview-${{ steps.build.outputs.id }}" | iconv -t ascii//TRANSLIT | sed -E 's/[~\^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+\|-+$//g' | sed -E 's/^-+//g' | sed -E 's/-+$//g' | tr A-Z a-z`
+ echo "site-url=https://$url_alias--${{ fromJSON(steps.netlify-config.outputs.result).siteUrl }}" >> $GITHUB_OUTPUT
+ netlify deploy --filter @swisspost/design-system-documentation --build false --dir ${{ steps.build.outputs.folder }} --alias $url_alias
- name: Update preview message
uses: ./.github/actions/preview/message/update
with:
access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
issue-number: ${{ steps.build.outputs.id }}
- preview-url: ${{ steps.deploy.outputs.preview-url }}
+ preview-url: ${{ steps.deploy.outputs.site-url }}
+
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ with:
+ script: |
+ return `# Deployed Documentation Preview
+ - SiteId: ${{ fromJSON(steps.netlify-config.outputs.result).siteId }}
+ - SiteUrl: ${{ steps.deploy.outputs.site-url }}
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml
index db263d82db..2d2c2057c7 100644
--- a/.github/workflows/e2e-tests.yaml
+++ b/.github/workflows/e2e-tests.yaml
@@ -20,7 +20,7 @@ jobs:
fetch-depth: 0
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
with:
use_cache: false
diff --git a/.github/workflows/fetch-icons.yaml b/.github/workflows/fetch-icons.yaml
index a87d9e5ee2..e89b09a8b5 100644
--- a/.github/workflows/fetch-icons.yaml
+++ b/.github/workflows/fetch-icons.yaml
@@ -32,7 +32,7 @@ jobs:
fetch-depth: 0
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
- name: Get Date
id: current-date
diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml
index f1f5577aa2..c9f383cbaf 100644
--- a/.github/workflows/lint.yaml
+++ b/.github/workflows/lint.yaml
@@ -19,7 +19,7 @@ jobs:
fetch-depth: 0
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
- name: Install dependencies of changed packages
run: pnpm install
diff --git a/.github/workflows/release-demo.yaml b/.github/workflows/release-demo.yaml
index a271c44362..56e4f6ce6e 100644
--- a/.github/workflows/release-demo.yaml
+++ b/.github/workflows/release-demo.yaml
@@ -1,6 +1,6 @@
###
#
-# Release the demo app whenever it's package json changes on the main branch
+# DEPRECATED: This Action can be removed as soon as we start working on V2/V9
#
###
@@ -33,7 +33,7 @@ jobs:
- name: Setup
if: steps.check.outputs.changed == 'true'
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
# Install changesets locally
- name: Install demo app & dependencies
diff --git a/.github/workflows/release-documentation.yaml b/.github/workflows/release-documentation.yaml
index efd2d8fdda..3bb15d595f 100644
--- a/.github/workflows/release-documentation.yaml
+++ b/.github/workflows/release-documentation.yaml
@@ -1,57 +1,91 @@
-###
-#
-# Release the documentation whenever it's package json changes on the main branch
-#
-###
-
-name: Release Documentation to Netlify
-
+name: Release Documentation
on:
push:
branches:
- main
+ - release/v*
paths:
- 'packages/documentation/package.json'
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
- release:
- name: Release Documentation
+ detect-version-change:
+ name: Detect Version Change
runs-on: ubuntu-latest
+ outputs:
+ changed: ${{ steps.check.outputs.changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
- - name: Check if version has changed
- id: check # This will be the reference for getting the outputs.
- uses: EndBug/version-check@v2 # You can choose the version/branch you prefer.
+ - name: Detect Version Change
+ id: check
+ uses: EndBug/version-check@v2
with:
file-name: ./packages/documentation/package.json
diff-search: true
token: ${{ secrets.GITHUB_TOKEN }}
- - name: Setup
- if: steps.check.outputs.changed == 'true'
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ with:
+ script: |
+ return `# Version Change Detection
+ A version change has ${${{ steps.check.outputs.changed == 'true' }} ? 'been' : 'NOT been'} detected.
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
+
+ release:
+ name: Release Documentation
+ runs-on: ubuntu-latest
+ needs: detect-version-change
+ if: needs.detect-version-change.outputs.changed == 'true'
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup pnpm & node
+ uses: ./.github/actions/setup-pnpm
- name: Install documentation & dependencies
- if: steps.check.outputs.changed == 'true'
run: pnpm --filter "design-system-documentation..." install
- name: Build documentation & dependencies
- if: steps.check.outputs.changed == 'true'
run: pnpm --filter "design-system-documentation..." build
- - name: Install netlify cli
- if: steps.check.outputs.changed == 'true'
- run: pnpm -g i netlify-cli@15
+ - name: Setup
+ uses: ./.github/actions/setup-netlify-cli
+
+ - name: Get Netlify Config
+ id: netlify-config
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs')
+ return JSON.parse(fs.readFileSync('./packages/documentation/netlify.config.json', 'utf8'))
- name: Publish documentation to netlify
- if: steps.check.outputs.changed == 'true'
+ id: deploy
env:
- NETLIFY_SITE_ID: ${{ secrets.NEXT_NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ NETLIFY_SITE_ID: ${{ fromJSON(steps.netlify-config.outputs.result).siteId }}
run: |
- netlify link --id $NETLIFY_SITE_ID
- netlify deploy --build false --dir packages/documentation/storybook-static --prod
+ echo "site-url=https://${{ fromJSON(steps.netlify-config.outputs.result).siteUrl }}" >> $GITHUB_OUTPUT
+ netlify deploy --filter @swisspost/design-system-documentation --build false --dir packages/documentation/storybook-static --prod
+
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ with:
+ script: |
+ return `# Deployed Documentation
+ - SiteId: ${{ fromJSON(steps.netlify-config.outputs.result).siteId }}
+ - SiteUrl: ${{ steps.deploy.outputs.site-url }}
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index f4339d6996..a8c2e6ad17 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -1,27 +1,25 @@
name: Release
-
on:
push:
branches:
- main
+ - release/v*
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
- release:
- name: Release
+ changeset-magic:
+ name: Set up Changeset PR or Release Packages
runs-on: ubuntu-latest
steps:
+ # Checkout the Branch which was pushed ('main' or 'release/v*')
- name: Checkout
uses: actions/checkout@v4
- with:
- fetch-depth: 0
- - name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ - name: Setup Node & pnpm
+ uses: ./.github/actions/setup-pnpm
- # Install dependencies and build packages
- - name: Install dependencies
+ - name: Install & build Dependencies
run: pnpm bootstrap
# This will fail the build if something in the publish setup is not correct
@@ -30,18 +28,411 @@ jobs:
run: pnpm -r publish --dry-run
# The changeset action will behave differently based on whether there are
- # new changesets on the main branch:
+ # new changesets on the github.ref branch:
#
# - new changesets: create a preview PR with the new version bumps and changelogs
- # - no new changesets (the preview PR got merged into main): publish packages
- - name: Changeset magic
+ # - no new changesets (the preview PR got merged into github.ref branch): publish packages
+ - name: Changeset Magic
id: changesets
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
- title: 'chore(changesets): 🦋📦 publish packages'
+ title: 'chore(changesets): 🦋📦 publish packages (${{ github.ref_name }})'
commit: 'chore(changesets): publish packages'
publish: pnpm changeset:publish
version: pnpm changeset:version
+
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ env:
+ PUBLISHED: ${{ steps.changesets.outputs.published }}
+ PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }}
+ with:
+ script: |
+ return `# Changesets
+ - Changesets published: ${process.env.PUBLISHED}
+ - Published Packages:
+
${JSON.stringify(JSON.parse(process.env.PUBLISHED_PACKAGES), null, 2)}+ ` + + - name: Output Summary + run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY + + # Only run this Job if: + # - Workflow runs on the 'main' Branch + collect-release-data: + name: Collect Release Data + runs-on: ubuntu-latest + needs: changeset-magic + if: github.ref_name == 'main' + outputs: + release-data: ${{ steps.release-data.outputs.result }} + changeset-branch-exists: ${{ steps.changeset-branch-exists.outputs.exists }} + release-branch-exists: ${{ steps.release-branch-exists.outputs.exists }} + release-changeset-branch-exists: ${{ steps.release-changeset-branch-exists.outputs.exists }} + steps: + # Checkout the Branch which has been pushed ('main' or 'release/v*') + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node & pnpm + uses: ./.github/actions/setup-pnpm + + - name: Install Dependencies + run: pnpm i + + # Create Status Files + - name: Create Status Files + run: | + pnpm m ls --depth=0 --json > monorepo.json + pnpm changeset status --output=changesets.json + + # Read the status Files and collect release data on the @swisspost/design-system-styles package + - name: Collect Release Data + id: release-data + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs') + const monorepo = JSON.parse(fs.readFileSync('monorepo.json', 'utf8')) + const styles = JSON.parse(fs.readFileSync('./packages/styles/package.json', 'utf8')) + const changesets = JSON.parse(fs.readFileSync('changesets.json', 'utf8')) + const release = changesets.releases.find(r => r.name === '@swisspost/design-system-styles') + + if (!release) return null + + const oldMajor = release.oldVersion.split('.')[0]; + const newMajor = release.newVersion.split('.')[0]; + const dependencies = monorepo + .filter(pkg => pkg.private === false && pkg.version !== undefined) + .reduce((packages, pkg) => ({ ...packages, [pkg.name]: pkg.version }), { ...(styles.peerDependencies ?? {}) }) + + return { + isMajor: release.type === 'major', + old: { + version: release.oldVersion, + major: oldMajor, + siteUrl: `design-system-version-${oldMajor}` + }, + new: { + version: release.newVersion, + major: newMajor, + siteUrl: 'design-system' + }, + branchName: `release/v${oldMajor}`, + dependencies + } + + - name: Check if changset-release/main Branch exists + id: changeset-branch-exists + uses: GuillaumeFalourd/branch-exists@v1 + with: + branch: changeset-release/main + + - name: Check if release/v* Branch exists + id: release-branch-exists + uses: GuillaumeFalourd/branch-exists@v1 + with: + branch: ${{ fromJSON(steps.release-data.outputs.result).branchName }} + + - name: Check if changeset-release/release/v* Branch exists + id: release-changeset-branch-exists + uses: GuillaumeFalourd/branch-exists@v1 + with: + branch: changeset-release/${{ fromJSON(steps.release-data.outputs.result).branchName }} + + - name: Create Summary + id: summary + uses: actions/github-script@v7 + env: + REF_NAME: ${{ github.ref_name }} + RELEASE_DATA: ${{ steps.release-data.outputs.result }} + CHANGESET_BRANCH_EXISTS: ${{ steps.changeset-branch-exists.outputs.exists }} + RELEASE_BRANCH_EXISTS: ${{ steps.release-branch-exists.outputs.exists }} + RELEASE_CHANGESET_BRANCH_EXISTS: ${{ steps.release-changeset-branch-exists.outputs.exists }} + with: + script: | + const release = JSON.parse(process.env.RELEASE_DATA) + const releaseBranch = release?.branchName ? `(
${release.branchName}
)` : ''
+ const releaseChangesetBranch = release?.branchName ? `(changeset-release/${release.branchName}
)` : ''
+
+ return `# Release Data
+ - Collecting Data: ${process.env.RELEASE_DATA === 'null' ? ':warning: WARNING: No Release Data found!' : ':rocket: SUCCESS!'}
+ ${JSON.stringify(release, null, 2)}+ - The Changeset Branch (
changeset-release/${process.env.REF_NAME}
) exists already: ${process.env.CHANGESET_BRANCH_EXISTS}
+ - The Release Branch ${releaseBranch} exists already: ${process.env.RELEASE_BRANCH_EXISTS}
+ - The Release-Changeset Branch ${releaseChangesetBranch} exists already: ${process.env.RELEASE_CHANGESET_BRANCH_EXISTS}
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
+
+ # Only run this Job if:
+ # - Workflow runs on the 'main' Branch
+ # - Release-Changeset Branch exists
+ # - Release Data exists
+ update-changeset-branch:
+ name: Update changeset-release/{main,release/v*} Branch
+ runs-on: ubuntu-latest
+ needs: collect-release-data
+ if: github.ref_name == 'main' && needs.collect-release-data.outputs.changeset-branch-exists == 'true' && fromJSON(needs.collect-release-data.outputs.release-data) != null
+ steps:
+ # Checkout the changeset Branch
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ ref: changeset-release/${{ github.ref_name }}
+
+ - name: Setup Node & pnpm
+ uses: ./.github/actions/setup-pnpm
+ with:
+ use_cache: false # do not use the pnpm cache if you do not install any dependencies
+
+ - name: Output Status Files
+ run: pnpm m ls --depth=0 --json > monorepo.json
+
+ # Only run this Step if a major release was detected
+ - name: Update or create Documentation _redirects
+ id: update-redirects
+ if: fromJSON(needs.collect-release-data.outputs.release-data).isMajor == true
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs')
+ const release = ${{ needs.collect-release-data.outputs.release-data }}
+
+ const redirectsPath = './packages/documentation/public/_redirects'
+ let redirects = ''
+ const redirect = `/v${release.old.major} https://${release.old.siteUrl}.netlify.app`
+
+ if (fs.existsSync(redirectsPath)) {
+ redirects = fs.readFileSync(redirectsPath, 'utf8')
+ } else {
+ redirects = '# Redirects from what the browser requests to what we serve\n'
+ }
+
+ if(!redirects.includes(redirect)) redirects += redirect
+ fs.writeFileSync(redirectsPath, redirects + '\n')
+
+ return true
+
+ - name: Update Documentation versions.json
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs')
+ const release = ${{ needs.collect-release-data.outputs.release-data }}
+
+ const versionsPath = './packages/documentation/public/assets/versions.json'
+ const versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'))
+ const monorepo = JSON.parse(fs.readFileSync('monorepo.json', 'utf8'))
+ const styles = JSON.parse(fs.readFileSync('./packages/styles/package.json', 'utf8'))
+
+ const currentVersion = versions.find(version => version.version.startsWith(release.old.major))
+ currentVersion.version = release.new.version
+ currentVersion.dependencies = release.dependencies
+
+ if (release.isMajor) {
+ currentVersion.version = release.old.version
+ currentVersion.url = `https://${release.old.siteUrl}.netlify.app`
+
+ const dependencies = monorepo
+ .filter(pkg => pkg.private === false && pkg.version !== undefined)
+ .reduce((packages, pkg) => ({ ...packages, [pkg.name]: pkg.version }), { ...(styles.peerDependencies ?? {}) })
+ versions.unshift({
+ title: `Version ${release.new.major}`,
+ version: release.new.version,
+ description: 'Pattern documentation, code snippets and implementation guidelines for the Design System Styles.',
+ url: `https://${release.new.siteUrl}.post.ch`,
+ dependencies
+ })
+ }
+
+ fs.writeFileSync(versionsPath, JSON.stringify(versions, null, 2) + '\n')
+
+ - name: Remove Status Files
+ run: rm -f monorepo.json
+
+ - name: Commit Changes and Push Branch
+ uses: EndBug/add-and-commit@v9
+ with:
+ message: 'chore(changesets): update release specific files'
+ push: true
+
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ env:
+ REF_NAME: ${{ github.ref_name }}
+ RELEASE_DATA: ${{ needs.collect-release-data.outputs.release-data }}
+ RELEASE_BRANCH_EXISTS: ${{ needs.collect-release-data.outputs.release-branch-exists }}
+ with:
+ script: |
+ const release = JSON.parse(process.env.RELEASE_DATA)
+
+ return `# Changeset Branch
+ The Release-Changeset Branch changeset-release/${process.env.REF_NAME}
has been created by the Changeset Action.
+ In addition to that, the following updates have been made to this Branch:
+ ${release.isMajor && process.env.RELEASE_BRANCH_EXISTS === 'false' ? `- Netlify _redirects
File has been created on to the changeset-release/${process.env.REF_NAME}
Branch.` : ''}
+ - The Netlify versions.json
File has been updated on to the changeset-release/${process.env.REF_NAME}
Branch.
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
+
+ # Only run this Job if:
+ # - Workflow runs on the 'main' Branch
+ # - Release Branch does not already exist
+ # - Release Data exists
+ # - A Major Release was detected
+ create-release-branch:
+ name: Create release/v* Branch
+ runs-on: ubuntu-latest
+ needs: collect-release-data
+ if: github.ref_name == 'main' && needs.collect-release-data.outputs.release-branch-exists == 'false' && fromJSON(needs.collect-release-data.outputs.release-data) != null && fromJSON(needs.collect-release-data.outputs.release-data).isMajor == true
+ steps:
+ # Checkout the commit with the release.old.version tag (e.g. @swisspost/design-system-styles@5.3.2)
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ ref: '@swisspost/design-system-styles@${{ fromJSON(needs.collect-release-data.outputs.release-data).old.version }}'
+
+ - name: Remove Documentation versions.json
+ run: rm -f ./packages/documentation/public/assets/versions.json
+
+ - name: Setup pnpm & node
+ uses: ./.github/actions/setup-pnpm
+
+ - name: Install documentation & dependencies
+ run: pnpm --filter "design-system-documentation..." install
+
+ - name: Build documentation & dependencies
+ run: pnpm --filter "design-system-documentation..." build
+
+ - name: Setup netlify-cli
+ uses: ./.github/actions/setup-netlify-cli
+
+ - name: Check if a Netlify Site with given siteUrl already exists
+ id: netlify-sites
+ env:
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ run: |
+ mkdir -p packages/documentation/.netlify
+ netlify sites:list --filter @swisspost/design-system-documentation --json > packages/documentation/.netlify/swisspost-sites.json
+ siteNames=$(jq -r '.[] | .name' packages/documentation/.netlify/swisspost-sites.json)
+ if [[ "$siteNames" == *"design-system-version-7-test"* ]]; then
+ echo "exists=true" >> $GITHUB_OUTPUT
+ else
+ echo "exists=false" >> $GITHUB_OUTPUT
+ fi
+
+ - name: Create Netlify Site (if it does not exist)
+ if: ${{ steps.netlify-site.outputs.exists == 'false' }}
+ env:
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ run: netlify sites:create --filter @swisspost/design-system-documentation --account-slug oliverschuerch --name ${{ fromJSON(needs.collect-release-data.outputs.release-data).old.siteUrl }} --manual
+
+ - name: Deploy Netlify Site
+ env:
+ NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
+ run: |
+ netlify link --filter @swisspost/design-system-documentation --name ${{ fromJSON(needs.collect-release-data.outputs.release-data).old.siteUrl }}
+ netlify deploy --filter @swisspost/design-system-documentation --build false --dir packages/documentation/storybook-static --prod
+
+ - name: Update Changeset config.json
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs')
+ const release = ${{ needs.collect-release-data.outputs.release-data }}
+
+ const changesetConfigPath = './.changeset/config.json'
+ const changesetConfig = JSON.parse(fs.readFileSync(changesetConfigPath, 'utf8'))
+ fs.writeFileSync(changesetConfigPath, JSON.stringify({
+ ...changesetConfig,
+ baseBranch: release.branchName
+ }, null, 2) + '\n')
+
+ - name: Update Documentation netlify.config.json
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const fs = require('fs')
+ const release = ${{ needs.collect-release-data.outputs.release-data }}
+
+ const netlifyState = JSON.parse(fs.readFileSync('./packages/documentation/.netlify/state.json', 'utf8'))
+ fs.writeFileSync('./packages/documentation/netlify.config.json', JSON.stringify({
+ ...netlifyState,
+ siteUrl: `${release.old.siteUrl}.netlify.app`
+ }, null, 2) + '\n')
+
+ # Commit the changes to a new release/v* branch
+ - name: Commit Changes and Push Release Branch
+ uses: EndBug/add-and-commit@v9
+ with:
+ new_branch: ${{ fromJSON(needs.collect-release-data.outputs.release-data).branchName }}
+ message: 'chore(setup): create "${{ fromJSON(needs.collect-release-data.outputs.release-data).branchName }}" branch'
+ push: true
+
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ env:
+ RELEASE_DATA: ${{ needs.collect-release-data.outputs.release-data }}
+ with:
+ script: |
+ const release = JSON.parse(process.env.RELEASE_DATA)
+
+ return `# Release Branch
+ - A new ${release.branchName}
Branch has been created.
+ - The file .changeset/config.json
(which holds the baseBranch
property) has been updated on to the ${release.branchName}
Branch.
+ - The file documentation/netlify.config.json
(which holds the siteId
and siteUrl
) has been created on to the ${release.branchName}
Branch.
+ - A new Netlify Page has been created and the build has been deployed to https://${release.old.siteUrl}.netlify.app
.
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
+
+ # Only run this Job if:
+ # - Workflow runs on the 'main' Branch
+ # - Either a Release Branch or a Changeset Branch exists
+ # - A non-Major Release was detected
+ remove-release-branch:
+ name: Remove release/v* Branch
+ runs-on: ubuntu-latest
+ needs: collect-release-data
+ if: github.ref_name == 'main' && (needs.collect-release-data.outputs.release-branch-exists == 'true' || needs.collect-release-data.outputs.release-changeset-branch-exists == 'true') && fromJSON(needs.collect-release-data.outputs.release-data) != null && fromJSON(needs.collect-release-data.outputs.release-data).isMajor == false
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Remove Changeset Branch
+ if: needs.collect-release-data.outputs.release-changeset-branch-exists == 'true'
+ env:
+ GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
+ run: git push origin --delete changeset-release/${{ fromJSON(needs.collect-release-data.outputs.release-data).branchName }}
+
+ - name: Remove Release Branch
+ if: needs.collect-release-data.outputs.release-branch-exists == 'true'
+ env:
+ GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
+ run: git push origin --delete ${{ fromJSON(needs.collect-release-data.outputs.release-data).branchName }}
+
+ - name: Create Summary
+ id: summary
+ uses: actions/github-script@v7
+ env:
+ RELEASE_DATA: ${{ needs.collect-release-data.outputs.release-data }}
+ with:
+ script: |
+ const release = JSON.parse(process.env.RELEASE_DATA)
+
+ return `# Release Branches
+ There once was a Changeset with a Major update, which has been deleted with the latest commit, therefore the before created ${release.branchName}
and changeset-release/${release.branchName}
Branches have been deleted.
+ `
+
+ - name: Output Summary
+ run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
diff --git a/.github/workflows/snapshot-tests.yaml b/.github/workflows/snapshot-tests.yaml
index 8b2986d694..2cc7df4fd7 100644
--- a/.github/workflows/snapshot-tests.yaml
+++ b/.github/workflows/snapshot-tests.yaml
@@ -25,7 +25,7 @@ jobs:
# Use cache is set to false because the cypress binary could not be cached correctly
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
with:
use_cache: false
diff --git a/.github/workflows/sonar-analysis.yaml b/.github/workflows/sonar-analysis.yaml
index 5e45ec0801..56e8147f27 100644
--- a/.github/workflows/sonar-analysis.yaml
+++ b/.github/workflows/sonar-analysis.yaml
@@ -22,10 +22,10 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
- fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
+ fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
- name: Install dependencies
run: pnpm install
@@ -33,5 +33,5 @@ jobs:
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml
index 787aba652b..26b9f0d5c8 100644
--- a/.github/workflows/unit-tests.yaml
+++ b/.github/workflows/unit-tests.yaml
@@ -20,7 +20,7 @@ jobs:
fetch-depth: 0
- name: Setup
- uses: swisspost/design-system/.github/actions/setup-pnpm@main
+ uses: ./.github/actions/setup-pnpm
# Install packages changed since main, as well as their dependants and dependencies
- name: Install dependencies
diff --git a/.gitignore b/.gitignore
index a5b4d2e7dc..a224a0eb80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,6 @@ styles/stylelint-report.txt
# Stencil
**/stencil-generated/
+
+# Local Netlify folder
+.netlify
diff --git a/package.json b/package.json
index 27a7d271f0..21ed75217c 100644
--- a/package.json
+++ b/package.json
@@ -86,10 +86,6 @@
"optionalDependencies": {
"@web-types/lit": "2.0.0-3"
},
- "engines": {
- "node": "20",
- "pnpm": "9"
- },
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
@@ -113,5 +109,8 @@
"follow-redirects@<=1.15.5": ">=1.15.6"
}
},
+ "engines": {
+ "node": "20"
+ },
"packageManager": "pnpm@9.3.0"
}
diff --git a/packages/documentation/netlify.config.json b/packages/documentation/netlify.config.json
new file mode 100644
index 0000000000..bf5b3bd5a9
--- /dev/null
+++ b/packages/documentation/netlify.config.json
@@ -0,0 +1,4 @@
+{
+ "siteId": "edc7287b-ec63-423c-84aa-c2a1cffbcf87",
+ "siteUrl": "design-system.post.ch"
+}
diff --git a/packages/documentation/public/_redirects b/packages/documentation/public/_redirects
new file mode 100644
index 0000000000..319cbe9237
--- /dev/null
+++ b/packages/documentation/public/_redirects
@@ -0,0 +1,5 @@
+# Redirects from what the browser requests to what we serve
+# This file is used by Netlify to handle redirects
+
+/v5 https://6401b58ebf0f4e298ee2dbe7--swisspost-web-frontend.netlify.app
+/v6 https://design-system-version-6.netlify.app