Skip to content

Commit

Permalink
chore: prepare v6 docs (#2985)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Schürch <[email protected]>
  • Loading branch information
gfellerph and oliverschuerch authored Jul 12, 2024
1 parent 9b36cdc commit b3e9ac2
Show file tree
Hide file tree
Showing 22 changed files with 733 additions and 200 deletions.
6 changes: 4 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"../packages/changelog-github/dist/index.js",
{ "repo": "swisspost/design-system" }
{
"repo": "swisspost/design-system"
}
],
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"baseBranch": "release/v6",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/hungry-rivers-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-documentation': patch
---

Updated netlify site configuration for v6 docs
86 changes: 9 additions & 77 deletions .github/actions/deploy-to-netlify/action.yaml
Original file line number Diff line number Diff line change
@@ -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
#
###

Expand All @@ -22,12 +11,6 @@ inputs:
id:
description: The build id
required: true
comment_token:
description: The access_token to use for commenting.
required: true
comment_author:
description: The authors name to use for commenting.
required: true
netlify_auth_token:
description: Netlify personal-access-token for use in shell scripts and API access.
required: true
Expand All @@ -43,77 +26,26 @@ inputs:
description: The package that will be deployed
required: true

outputs:
preview-url:
description: The deployed preview url.
value: https://${{ steps.netlify_deploy.outputs.url_alias }}--${{ inputs.netlify_site_url }}

runs:
using: composite
steps:
- name: Find Preview Comment
uses: peter-evans/find-comment@v2
id: preview_comment
with:
token: ${{ inputs.comment_token }}
issue-number: ${{ inputs.id }}
comment-author: ${{ inputs.comment_author }}
body-includes: Preview environment ready

- name: Create Initial Preview Comment
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.preview_comment.outputs.comment-id == 0 }}
with:
token: ${{ inputs.comment_token }}
issue-number: ${{ inputs.id }}
edit-mode: replace
body: Preview environments are getting posted here, as soon as they are ready!
reactions: eyes

- name: Find Initial Preview Comment
uses: peter-evans/find-comment@v2
id: initial_preview_comment
with:
token: ${{ inputs.comment_token }}
issue-number: ${{ inputs.id }}
comment-author: ${{ inputs.comment_author }}
body-includes: Preview environments are getting posted here, as soon as they are ready!

- name: Install netlify-cli
shell: bash
run: pnpm i -g netlify-cli@16
run: pnpm i -g netlify-cli@17

- 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
- name: Prepare Comment Message
id: comment
shell: bash
run: |
echo "message=Preview environment ready: https://${{ steps.netlify_deploy.outputs.url_alias }}--${{ inputs.netlify_site_url }}" >> $GITHUB_OUTPUT
- name: Replace Preview Comment
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.initial_preview_comment.outputs.comment-id != 0 }}
with:
token: ${{ inputs.comment_token }}
comment-id: ${{ steps.initial_preview_comment.outputs.comment-id }}
issue-number: ${{ inputs.id }}
edit-mode: replace
body: ${{ steps.comment.outputs.message }}
reactions: rocket

- name: Append Preview Comment
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.initial_preview_comment.outputs.comment-id == 0 && (steps.preview_comment.outputs.comment-id == 0 || !contains(steps.preview_comment.outputs.comment-body, steps.comment.outputs.message)) }}
with:
token: ${{ inputs.comment_token }}
comment-id: ${{ steps.preview_comment.outputs.comment-id }}
issue-number: ${{ inputs.id }}
edit-mode: append
body: ${{ steps.comment.outputs.message }}
reactions: rocket
netlify deploy --filter ${{inputs.package_name}} --build false --dir ${{ inputs.folder }} --alias $url_alias
52 changes: 52 additions & 0 deletions .github/actions/preview/message/create/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Create preview message
description: Add a preview comment to the pr, if not already present

inputs:
access-token:
description: The access token to use for commenting.
required: true

runs:
using: composite
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ inputs.access-token }}
script: |
const commentTitle = '**Related Previews**'
const commentInitialBody = 'Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)'
let comments
let previewComment
await getPreviewComment()
if (!previewComment) {
await github.rest.issues.createComment({
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: context.issue.number,
body: `${commentTitle}\n${commentInitialBody}`
})
await getPreviewComment()
github.rest.reactions.createForIssueComment({
repo: context.repo.repo,
owner: context.repo.owner,
comment_id: previewComment.id,
content: 'eyes'
})
} else {
console.info('Skipped action, because preview comment already existed.')
}
async function getPreviewComment () {
comments = (await github.rest.issues.listComments({
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: context.issue.number
})).data || []
previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle))
}
74 changes: 74 additions & 0 deletions .github/actions/preview/message/update/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Update preview message
description: Add a preview url to the existing preview comment, if not already present

inputs:
access-token:
description: The access token to use for commenting.
required: true
issue-number:
description: The issue number from the caller workflow.
required: true
preview-url:
description: The preview url to add in the comment.
required: true

runs:
using: composite
steps:
- uses: actions/github-script@v7
env:
ISSUE_NUMBER: ${{ inputs.issue-number }}
PREVIEW_URL: ${{ inputs.preview-url }}
with:
github-token: ${{ inputs.access-token }}
script: |
const { ISSUE_NUMBER, PREVIEW_URL } = process.env
const commentTitle = '**Related Previews**'
const commentInitialBody = 'Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)'
const comments = (await github.rest.issues.listComments({
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: Number(ISSUE_NUMBER)
})).data || []
const previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle))
if (previewComment && !previewComment.body.includes(PREVIEW_URL)) {
github.rest.issues.updateComment({
repo: context.repo.repo,
owner: context.repo.owner,
comment_id: previewComment.id,
body: previewComment.body
.replace(commentInitialBody, '')
.concat(`- ${PREVIEW_URL}\n`)
})
const reactions = (await github.rest.reactions.listForIssueComment({
repo: context.repo.repo,
owner: context.repo.owner,
comment_id: previewComment.id,
})).data || []
const createReaction = reactions.find(r => r.user.login === 'swisspost-bot' && r.content === 'eyes')
const updateReaction = reactions.find(r => r.user.login === 'swisspost-bot' && r.content === 'rocket')
if (createReaction) {
github.rest.reactions.deleteForIssueComment({
repo: context.repo.repo,
owner: context.repo.owner,
comment_id: previewComment.id,
reaction_id: createReaction.id
})
}
if (!updateReaction) {
github.rest.reactions.createForIssueComment({
repo: context.repo.repo,
owner: context.repo.owner,
comment_id: previewComment.id,
content: 'rocket'
})
}
} else {
console.warn('Skipped action, because preview comment could not be found!')
}
15 changes: 15 additions & 0 deletions .github/actions/setup-netlify-cli/action.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 16 additions & 5 deletions .github/actions/setup-pnpm/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ description: Provides node and pnpm in a specific version.
inputs:
node_version:
description: Specify the node version to install
default: 18
type: string
pnpm_version:
description: Specify the pnpm version to install
default: 8
type: string
use_cache:
description: Specify wether to use the pnpm cache or not
Expand All @@ -40,13 +38,26 @@ inputs:
runs:
using: composite
steps:
- name: Detect wanted Node & pnpm version
id: env-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.engines?.pnpm
}
- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3
with:
version: ${{ inputs.pnpm_version }}
version: ${{ inputs.pnpm_version || fromJSON(steps.env-versions.outputs.result).pnpm }}

- name: Install node with pnpm cache
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}
node-version: ${{ inputs.node_version || fromJSON(steps.env-versions.outputs.result).node }}
cache: ${{ inputs.use_cache == 'true' && 'pnpm' || '' }}
19 changes: 9 additions & 10 deletions .github/workflows/build-demo.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
###
#
# 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
#
###

name: Build Demo App
on:
pull_request:
types: [opened, synchronize, edited, reopened]
paths:
- 'packages/intranet-header-workspace/**'
- 'packages/demo/**'
Expand All @@ -29,16 +23,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Create preview message
uses: ./.github/actions/preview/message/create
with:
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: |
pnpm --filter design-system-demo... install
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
Loading

0 comments on commit b3e9ac2

Please sign in to comment.