Skip to content

Commit

Permalink
chore(workflows): align documentation and release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschuerch committed Jul 11, 2024
1 parent 02c9fe3 commit 8a1b14a
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
name: Build Documentation
on:
pull_request:
types: [opened, synchronize, edited, reopened]
paths:
- 'packages/**'

jobs:
build:
name: Build Documentation
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
50 changes: 29 additions & 21 deletions .github/workflows/deploy-documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
###
#
# 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']
types: [completed]

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
- 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
id: build
Expand All @@ -39,20 +34,33 @@ jobs:
const fs = require('fs')
return JSON.parse(fs.readFileSync('./packages/documentation/netlify.config.json', 'utf8'))
- name: Deploy documentation to netlify
uses: ./.github/actions/deploy-to-netlify
- name: Deploy Documentation Preview
id: deploy
with:
id: ${{ steps.build.outputs.id }}
netlify_auth_token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify_site_id: ${{ fromJSON(steps.netlify-config.outputs.result).siteId }}
netlify_site_url: ${{ fromJSON(steps.netlify-config.outputs.result).siteUrl }}
folder: ${{ steps.build.outputs.folder }}
package_name: '@swisspost/design-system-documentation'
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: <code>${{ fromJSON(steps.netlify-config.outputs.result).siteId }}</code>
- SiteUrl: ${{ steps.deploy.outputs.site-url }}
`
- name: Output Summary
run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
64 changes: 42 additions & 22 deletions .github/workflows/release-documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
###
#
# 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:
check-version:
name: Check Version
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: 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: check-version
if: needs.check-version.outputs.changed == 'true'
needs: detect-version-change
if: needs.detect-version-change.outputs.changed == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup
- name: Setup pnpm & node
uses: ./.github/actions/setup-pnpm

- name: Install documentation & dependencies
Expand All @@ -53,10 +57,10 @@ jobs:
- name: Build documentation & dependencies
run: pnpm --filter "design-system-documentation..." build

- name: Install netlify cli
run: pnpm -g i netlify-cli
- name: Setup netlify-cli
uses: ./.github/actions/setup-netlify-cli

- name: Get netlify config
- name: Get Netlify Config
id: netlify-config
uses: actions/github-script@v7
with:
Expand All @@ -65,7 +69,23 @@ jobs:
return JSON.parse(fs.readFileSync('./packages/documentation/netlify.config.json', 'utf8'))
- name: Publish documentation to netlify
id: deploy
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ fromJSON(steps.netlify-config.outputs.result).siteId }}
run: netlify deploy --filter @swisspost/design-system-documentation --build false --dir packages/documentation/storybook-static --prod
run: |
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: <code>${{ fromJSON(steps.netlify-config.outputs.result).siteId }}</code>
- SiteUrl: ${{ steps.deploy.outputs.site-url }}
`
- name: Output Summary
run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY
Loading

0 comments on commit 8a1b14a

Please sign in to comment.