Update produktions-og-testmiljoe.md #1843
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: GitHub Pages | |
on: | |
push: | |
branches: ["*"] | |
delete: | |
branches: ["*"] | |
env: | |
GITHUB_PAGES_BRANCH: "gh-pages" | |
GITHUB_PAGES_ROOT_DIR: "./gh-pages-root" | |
BUILD_DIR: "./build" | |
REPO_NAME: 'folkebibliotekernes_cms_manual' | |
PREVIEW_SUBDIR: 'preview' | |
permissions: | |
contents: write | |
deployments: write | |
jobs: | |
build: | |
name: "Build and deploy Jekyll site" | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Prepare documentation root | |
run: | | |
mkdir -p ${{ env.GITHUB_PAGES_ROOT_DIR }} | |
echo "<!DOCTYPE html> | |
<html> | |
<head><meta http-equiv=\"refresh\" content=\"0; url='./main/'\" /></head> | |
<body><p>You will be redirected to the documentation</p></body> | |
</html>" > ${{ env.GITHUB_PAGES_ROOT_DIR }}/index.html | |
- name: Deploy documentation root | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_branch: ${{ env.GITHUB_PAGES_BRANCH }} | |
publish_dir: ${{ env.GITHUB_PAGES_ROOT_DIR }} | |
destination_dir: "." | |
keep_files: true | |
commit_message: "Create root index.html" | |
- name: Get branch names | |
id: branch-name | |
uses: tj-actions/branch-names@v7 | |
- name: Set GitHub Pages directory | |
id: github-pages | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "directory=main" >> $GITHUB_OUTPUT | |
echo "url=https://${{ github.repository_owner }}.github.io/${{ env.REPO_NAME }}/main" >> $GITHUB_OUTPUT | |
else | |
echo "directory=preview/${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_OUTPUT | |
echo "url=https://${{ github.repository_owner }}.github.io/${{ env.REPO_NAME }}/${{ env.PREVIEW_SUBDIR }}/${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Configure GitHub Pages | |
id: pages | |
uses: actions/configure-pages@v3 | |
- name: Set Jekyll base url | |
uses: fjogeleit/yaml-update-action@main | |
with: | |
valueFile: '_config.yml' | |
propertyPath: 'baseurl' | |
value: '/${{ steps.github-pages.outputs.directory }}' | |
commitChange: false | |
- name: Build Jekyll site | |
uses: actions/jekyll-build-pages@v1 | |
with: | |
destination: ${{ env.BUILD_DIR }} | |
- name: Start deployment | |
uses: bobheadxi/deployments@v1 | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ steps.branch-name.outputs.current_branch }} | |
- name: Deploy Jekyll site to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_branch: ${{ env.GITHUB_PAGES_BRANCH }} | |
publish_dir: ${{ env.BUILD_DIR }} | |
destination_dir: ${{ steps.github-pages.outputs.directory }} | |
enable_jekyll: false | |
commit_message: "Create/update Jekyll site for ${{ steps.branch-name.outputs.current_branch }}" | |
- name: Wait for deployment to become available | |
uses: iFaxity/wait-on-action@v1 | |
with: | |
resource: ${{ steps.github-pages.outputs.url }} | |
- name: Update deployment status | |
uses: bobheadxi/deployments@v1 | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
env: ${{ steps.deployment.outputs.env }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
env_url: ${{ steps.github-pages.outputs.url }} | |
delete: | |
name: "Cleanup preview" | |
if: github.event_name == 'delete' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ env.GITHUB_PAGES_BRANCH }} | |
# We cannot use tj-actions/branch-names to get the name of the deleted | |
# branch as it will already be deleted when this runs. | |
- name: Delete preview site | |
run: | | |
rm -rf ${{ env.PREVIEW_SUBDIR }}/${{ github.event.ref }} | |
- uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "Delete preview Jekyll site for ${{ github.event.ref }}" | |
- name: Deactivate environment | |
uses: bobheadxi/deployments@v1 | |
with: | |
step: deactivate-env | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ github.event.ref }} |