Skip to content

Icon: Customizable icon asset path #6702

Icon: Customizable icon asset path

Icon: Customizable icon asset path #6702

Workflow file for this run

name: Build & Deploy Cookbook
on:
push:
branches:
- develop
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
defaults:
run:
shell: bash
jobs:
pre_build:
name: Check if build is needed
runs-on: ubuntu-latest
outputs:
#Build on PRs, PR's merge to default branch, new releases & changes not including 'libs' (which gets build as part of new release)
do_build: ${{ github.event_name == 'pull_request' || github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v') || steps.filter.outputs.libs == 'false' }}
node_version: ${{ steps.get_node_version.outputs.node_version }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Check modified files
id: filter
uses: dorny/[email protected]
with:
filters: |
libs:
- 'libs/**'
- name: Get Node.JS version from package.json
id: get_node_version
run: echo ::set-output name=node_version::$(jq -r .engines.node ./package.json)
lint_and_unittest:
name: Lint & unit test
needs: pre_build
if: ${{ needs.pre_build.outputs.do_build == 'true' }}
runs-on: ubuntu-latest
env:
NODE_VERSION: ${{ needs.pre_build.outputs.node_version }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Kirby setup
uses: ./.github/actions/kirby-setup
- name: Run linting
run: npx nx run-many -t lint && npx stylelint '**/*.scss'
- name: Run tests
run: npx nx run-many -t test --output-style=stream -- --browsers=ChromeCustom --progress false --watch false --code-coverage
build_kirby:
name: Build Kirby lib
needs: pre_build
if: ${{ needs.pre_build.outputs.do_build == 'true' }}
runs-on: ubuntu-latest
env:
NODE_VERSION: ${{ needs.pre_build.outputs.node_version }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Kirby setup
uses: ./.github/actions/kirby-setup
- name: Build Kirby lib
run: npx nx build designsystem
build_kirby_cookbook:
name: Build Kirby Cookbook
needs: pre_build
if: ${{ needs.pre_build.outputs.do_build == 'true' }}
runs-on: ubuntu-latest
env:
NODE_VERSION: ${{ needs.pre_build.outputs.node_version }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Kirby setup
uses: ./.github/actions/kirby-setup
- name: Build Kirby Cookbook
run: npx nx build cookbook --configuration=production
- name: Upload Kirby Cookbook dist files
uses: actions/cache@v2
with:
path: |
dist/
key: cookbook-dist-${{github.run_id}}
deploy_to_cookbook:
name: Deploy cookbook
needs: [lint_and_unittest, build_kirby, build_kirby_cookbook]
runs-on: ubuntu-latest
env:
DOMAIN: 'kirby.design'
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Get deployment name for default or feature branch
if: "github.event_name == 'pull_request' || github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v')"
run: |
branchname="${{ github.head_ref || github.ref }}"
echo "Github branchname: ${branchname}"
branchname="${branchname##*/}"
echo "Removed leading paths - branchname: ${branchname}"
branchname=$(tr [:upper:] [:lower:] <<< "$branchname")
echo "Converted to lowercase - branchname: ${branchname}"
branchname="${branchname//[^a-zA-Z0-9]/-}"
echo "Replaced illegal chars - branchname: ${branchname}"
branchname=$(tr -s '-' '-' <<< "$branchname")
echo "Removed duplicated dashes - branchname: ${branchname}"
branchname="${branchname%%-}"
echo "Removed trailing dash - final branchname: ${branchname}"
releasename="kby-${branchname}"
releasename=$(cut -c 1-53 <<< "$releasename")
echo "Releasename: ${releasename}"
echo "GH_DEPLOY_ENVIRONMENT=pr-${branchname}" >> $GITHUB_ENV
echo "RELEASENAME=${releasename}" >> $GITHUB_ENV
- name: Get deployment name for release branch
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')"
run: |
echo "GH_DEPLOY_ENVIRONMENT=production" >> $GITHUB_ENV
echo "RELEASENAME=designsystem" >> $GITHUB_ENV
- name: Get hostname for default or feature branch
if: "github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v')"
run: |
chmod +x ./scripts/dns.pl
hostname=$(perl ./scripts/dns.pl $DOMAIN "${RELEASENAME}")
echo "HOSTNAME=${hostname}" >> $GITHUB_ENV
- name: Get hostname for release branch
if: "github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')"
run: echo "HOSTNAME=cookbook" >> $GITHUB_ENV
- name: Create Github Deployment
id: create_deployment
uses: octokit/[email protected]
with:
route: POST /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.head_ref) || github.ref }}
environment: ${{ env.GH_DEPLOY_ENVIRONMENT }}
production_environment: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
auto_merge: false
required_contexts: '[]' # Skip commit checks
mediaType: '{"previews": ["flash", "ant-man"]}' # some parameters need preview: https://docs.github.com/en/rest/reference/repos#list-deployment-statuses-preview-notices
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set deployment status to in progress
uses: octokit/[email protected]
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download Kirby Cookbook dist files
uses: actions/cache@v2
with:
path: |
dist/
key: cookbook-dist-${{github.run_id}}
- name: Deploy cookbook to GitHub pages
run: |
set -e
echo "Hostname: ${HOSTNAME}"
git clone https://$GITHUB_ACTOR:[email protected]/kirbydesign/designsystem.git -b gh-pages designsystem_web
git config --global user.name 'DRB-bot'
git config --global user.email '[email protected]'
mkdir -p designsystem_web/branch
if [ $HOSTNAME == "cookbook" ]; then
sed -i -E "s,<base href=\"[^\"]*\".*>,<base href=\"/\">,g" dist/apps/cookbook/index.html
cp -R dist/apps/cookbook/* designsystem_web/
cp designsystem_web/index.html designsystem_web/404.html
else
mkdir -p designsystem_web/branch/$HOSTNAME
sed -i -E "s,<base href=\"[^\"]*\".*>,<base href=\"/branch/$HOSTNAME/\">,g" dist/apps/cookbook/index.html
cp -R dist/apps/cookbook/* designsystem_web/branch/$HOSTNAME
cp designsystem_web/branch/$HOSTNAME/index.html designsystem_web/branch/$HOSTNAME/404.html
fi
cd designsystem_web/branch/
folders=$(ls -d */)
cd ../
branches=$(git branch -r)
#find deployment names for all branches
branchList=""
for branch in $branches; do
name="${branch##*/}"
name=$(tr [:upper:] [:lower:] <<< "$name")
name="${name//[^a-zA-Z0-9]/-}"
name=$(tr -s '-' '-' <<< "$name")
name="${name%%-}"
name="kby-${name}"
name=$(cut -c 1-53 <<< "$name")
branchList="$branchList $name"
done
#delete deployments related to closed branches
for item in $folders
do
echo "Verify branch ${item::-1} exist"
if ! grep -q "${item::-1}" <<< "$branchList"; then
echo "Deleting branch folder ${item::-1} (branch closed)"
rm -Rf branch/${item::-1}
fi
done
git add .
if ! git diff-index --quiet HEAD; then
git commit -m "Release: $RELEASENAME"
git push
fi
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set deployment status to success
id: successful_deployment
uses: octokit/[email protected]
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment_url: ${{ env.HOSTNAME == 'cookbook' && format('https://cookbook.{0}', env.DOMAIN) || format('https://cookbook.{0}/branch/{1}/index.html', env.DOMAIN, env.HOSTNAME) }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: success
mediaType: '{"previews": ["ant-man"]}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set deployment status to failure
id: failed_deployment
uses: octokit/[email protected]
if: failure()
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: failure
mediaType: '{"previews": ["ant-man"]}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}