Migration notes Kirby v9 #5508
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/paths-filter@v2.9.2 | |
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: npm run lint | |
- name: Run tests | |
run: npm run test:ci | |
- name: Generate coverage report | |
run: npm run coverage-report || true | |
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: npm run dist: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: npm run dist:cookbook | |
- 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/request-action@v2.x | |
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/request-action@v2.x | |
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:$GITHUB_TOKEN@github.com/kirbydesign/designsystem.git -b gh-pages designsystem_web | |
git config --global user.name 'DRB-bot' | |
git config --global user.email 'dbrr00@bankdata.dk' | |
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/request-action@v2.x | |
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/request-action@v2.x | |
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 }} |