diff --git a/.github/dependabot.yml b/.github/dependabot.yml index dc8b2fd..3429a9d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,6 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - +--- version: 2 + updates: - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/workflows/cicd-build-docker-image.yml b/.github/workflows/cicd-build-docker-image.yml deleted file mode 100644 index cc14d71..0000000 --- a/.github/workflows/cicd-build-docker-image.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: ♻️ Build Docker Image - -on: - workflow_dispatch: - pull_request: - branch: main - -jobs: - build_docker_image: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build - uses: docker/build-push-action@v4 - with: - push: false \ No newline at end of file diff --git a/.github/workflows/cicd-build-test.yml b/.github/workflows/cicd-build-test.yml new file mode 100644 index 0000000..b670484 --- /dev/null +++ b/.github/workflows/cicd-build-test.yml @@ -0,0 +1,41 @@ +--- +name: ♻️ Build and Test + +on: + pull_request: + branches: + - main + +permissions: {} + +jobs: + build-test: + name: Build and Test + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Build + id: build + shell: bash + run: | + docker build --file Dockerfile --tag ministryofjustice/tech-docs-github-pages-publisher:latest . + + - name: Package + id: package + shell: bash + run: | + docker run --rm \ + --volume ${GITHUB_WORKSPACE}/test:/app \ + ministryofjustice/tech-docs-github-pages-publisher:latest /usr/local/bin/package + + - name: Lychee + id: lychee + uses: lycheeverse/lychee-action@c053181aa0c3d17606addfe97a9075a32723548a # v1.9.3 + with: + args: --verbose --no-progress './**/*.md' './**/*.html' './**/*.erb' --accept 403,200,429 + fail: true diff --git a/.github/workflows/cicd-dependency-review.yml b/.github/workflows/cicd-dependency-review.yml index 268e7af..03e09f3 100644 --- a/.github/workflows/cicd-dependency-review.yml +++ b/.github/workflows/cicd-dependency-review.yml @@ -1,20 +1,28 @@ -# Need a GitHub Advanced Security license to run this action on private repos. - +--- name: ♻️ Dependency Review + on: pull_request: - branch: main + types: + - edited + - opened + - reopened + - synchronize -permissions: - contents: read +permissions: {} jobs: dependency-review: + name: Dependency Review runs-on: ubuntu-latest + permissions: + contents: read steps: - - name: Checkout Repository - uses: actions/checkout@v4 + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Dependency Review - uses: actions/dependency-review-action@v3 + uses: actions/dependency-review-action@9129d7d40b8c12c1ed0f60400d00c92d437adcce # v4.1.3 with: fail-on-severity: critical diff --git a/.github/workflows/cicd-push-docker-image.yml b/.github/workflows/cicd-push-docker-image.yml deleted file mode 100644 index 8cdf2d7..0000000 --- a/.github/workflows/cicd-push-docker-image.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: ♻️ Push Docker Image - -on: - workflow_dispatch: - inputs: - release_tag: - type: string - description: Release tag for docker image. In format `v{x}.{y}.{z}` i.e `v3.0.1` - required: true - -jobs: - push_to_registry: - name: Push Docker Image - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and Push - uses: docker/build-push-action@v4 - with: - push: true - tags: ministryofjustice/tech-docs-github-pages-publisher:${{ inputs.release_tag }} - - - name: Report failure to Slack - if: always() - uses: ravsamhq/notify-slack-action@v2 - with: - status: ${{ job.status }} - notify_when: "failure" - notification_title: "Failed GitHub Action Run" - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/cicd-release.yml b/.github/workflows/cicd-release.yml new file mode 100644 index 0000000..3ee22be --- /dev/null +++ b/.github/workflows/cicd-release.yml @@ -0,0 +1,45 @@ +--- +name: ♻️ Release + +on: + push: + tags: + - "v*" + +permissions: {} + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Log in to Docker Hub + id: login_dockerhub + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and Push + id: build_and_push + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 + with: + push: true + tags: ministryofjustice/tech-docs-github-pages-publisher:${{ github.ref_name }} + + - name: Report failure to Slack + id: slack_failure + if: always() + uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v2.5.0 + with: + status: ${{ job.status }} + notify_when: "failure" + notification_title: "Failed GitHub Action Run" + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.gitignore b/.gitignore index ea1f0ff..a2d8575 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,14 @@ .env - +.terraform/ +coverage/ +venv/ +env/ +.DS_STORE .vscode -.idea +*.code-workspace +*.sha256 +terraform.tfstate +test/docs +test/artifact.tar +test/config.rb +test/Gemfile* diff --git a/.lycheeignore b/.lycheeignore new file mode 100644 index 0000000..dbb83e5 --- /dev/null +++ b/.lycheeignore @@ -0,0 +1,2 @@ +https://ministryofjustice.github.io/tech-docs-github-pages-publisher +https://github.com/ministryofjustice/tech-docs-github-pages-publisher diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 49cdd66..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.7.6 diff --git a/Dockerfile b/Dockerfile index 78d1f0b..085b662 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,24 @@ -# Do not update to Ruby 3 until Gemfile dependencies are fixed -FROM ruby:2.7.6-alpine3.15 +FROM docker.io/ruby:3.2.3-alpine3.19 -# These are needed to support building native extensions during -# bundle install step -RUN apk --update add --virtual build_deps build-base git +ENV BUNDLER_VERSION="2.5.6" -RUN addgroup -g 1000 -S appgroup \ - && adduser -u 1000 --system appuser \ - && adduser appuser appgroup \ - && gem install bundler -v 2.4.22\ - && bundle config +RUN apk --update-cache --no-cache add \ + build-base \ + git \ + nodejs -# Required at runtime by middleman -RUN apk add --no-cache nodejs +RUN gem install bundler --version "${BUNDLER_VERSION}" -WORKDIR /app +# Adding package and preview scripts +COPY bin/ /usr/local/bin/ + +# Copy Gemfile and Gemfile.lock, install gems and store them for packaging and preview scripts +WORKDIR /opt/publisher -COPY Gemfile Gemfile.lock ./ +COPY src/opt/publisher/ /opt/publisher/ RUN bundle install -# Stash a copy of the config.rb, Gemfile and Gemfile.lock Middleman need these -# later, because documentation repos won't have them. -RUN mkdir /stashed-files -COPY config.rb Gemfile Gemfile.lock /stashed-files/ +WORKDIR /app -RUN mkdir /publishing-scripts -COPY scripts/* /scripts/ +ENTRYPOINT ["/bin/sh"] diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 7d2fcff..0000000 --- a/Gemfile +++ /dev/null @@ -1,13 +0,0 @@ -source "https://rubygems.org" - -# Fixed as Date exception occurs in govuk_tech_docs for review_date -# when use ruby 3.x -ruby "2.7.6" - -gem "govuk_tech_docs" - -# Fixed as v5.x requires ruby 3.x -gem "html-proofer", "=4.4.3" - -# Fixed as v6.x has an issue when run Middleman build command -gem "haml", "=5.2.2" diff --git a/LICENSE b/LICENSE index 53701c9..d27ec55 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2022 Crown Copyright (Ministry of Justice) +Copyright (c) 2020-2024 Crown Copyright (Ministry of Justice) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 74eb763..accf4cd 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,23 @@ [![Releases](https://img.shields.io/github/release/ministryofjustice/tech-docs-github-pages-publisher/all.svg?style=flat-square)](https://github.com/ministryofjustice/tech-docs-github-pages-publisher/releases) [![repo standards badge](https://img.shields.io/endpoint?labelColor=231f20&color=005ea5&style=for-the-badge&label=MoJ%20Compliant&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fendpoint%2Ftech-docs-github-pages-publisher&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAHJElEQVRYhe2YeYyW1RWHnzuMCzCIglBQlhSV2gICKlHiUhVBEAsxGqmVxCUUIV1i61YxadEoal1SWttUaKJNWrQUsRRc6tLGNlCXWGyoUkCJ4uCCSCOiwlTm6R/nfPjyMeDY8lfjSSZz3/fee87vnnPu75z3g8/kM2mfqMPVH6mf35t6G/ZgcJ/836Gdug4FjgO67UFn70+FDmjcw9xZaiegWX29lLLmE3QV4Glg8x7WbFfHlFIebS/ANj2oDgX+CXwA9AMubmPNvuqX1SnqKGAT0BFoVE9UL1RH7nSCUjYAL6rntBdg2Q3AgcAo4HDgXeBAoC+wrZQyWS3AWcDSUsomtSswEtgXaAGWlVI2q32BI0spj9XpPww4EVic88vaC7iq5Hz1BvVf6v3qe+rb6ji1p3pWrmtQG9VD1Jn5br+Knmm70T9MfUh9JaPQZu7uLsR9gEsJb3QF9gOagO7AuUTom1LpCcAkoCcwQj0VmJregzaipA4GphNe7w/MBearB7QLYCmlGdiWSm4CfplTHwBDgPHAFmB+Ah8N9AE6EGkxHLhaHU2kRhXc+cByYCqROs05NQq4oR7Lnm5xE9AL+GYC2gZ0Jmjk8VLKO+pE4HvAyYRnOwOH5N7NhMd/WKf3beApYBWwAdgHuCLn+tatbRtgJv1awhtd838LEeq30/A7wN+AwcBt+bwpD9AdOAkYVkpZXtVdSnlc7QI8BlwOXFmZ3oXkdxfidwmPrQXeA+4GuuT08QSdALxC3OYNhBe/TtzON4EziZBXD36o+q082BxgQuqvyYL6wtBY2TyEyJ2DgAXAzcC1+Xxw3RlGqiuJ6vE6QS9VGZ/7H02DDwAvELTyMDAxbfQBvggMAAYR9LR9J2cluH7AmnzuBowFFhLJ/wi7yiJgGXBLPq8A7idy9kPgvAQPcC9wERHSVcDtCfYj4E7gr8BRqWMjcXmeB+4tpbyG2kG9Sl2tPqF2Uick8B+7szyfvDhR3Z7vvq/2yqpynnqNeoY6v7LvevUU9QN1fZ3OTeppWZmeyzRoVu+rhbaHOledmoQ7LRd3SzBVeUo9Wf1DPs9X90/jX8m/e9Rn1Mnqi7nuXXW5+rK6oU7n64mjszovxyvVh9WeDcTVnl5KmQNcCMwvpbQA1xE8VZXhwDXAz4FWIkfnAlcBAwl6+SjD2wTcmPtagZnAEuA3dTp7qyNKKe8DW9UeBCeuBsbsWKVOUPvn+MRKCLeq16lXqLPVFvXb6r25dlaGdUx6cITaJ8fnpo5WI4Wuzcjcqn5Y8eI/1F+n3XvUA1N3v4ZamIEtpZRX1Y6Z/DUK2g84GrgHuDqTehpBCYend94jbnJ34DDgNGArQT9bict3Y3p1ZCnlSoLQb0sbgwjCXpY2blc7llLW1UAMI3o5CD4bmuOlwHaC6xakgZ4Z+ibgSxnOgcAI4uavI27jEII7909dL5VSrimlPKgeQ6TJCZVQjwaOLaW8BfyWbPEa1SaiTH1VfSENd85NDxHt1plA71LKRvX4BDaAKFlTgLeALtliDUqPrSV6SQCBlypgFlbmIIrCDcAl6nPAawmYhlLKFuB6IrkXAadUNj6TXlhDcCNEB/Jn4FcE0f4UWEl0NyWNvZxGTs89z6ZnatIIrCdqcCtRJmcCPwCeSN3N1Iu6T4VaFhm9n+riypouBnepLsk9p6p35fzwvDSX5eVQvaDOzjnqzTl+1KC53+XzLINHd65O6lD1DnWbepPBhQ3q2jQyW+2oDkkAtdt5udpb7W+Q/OFGA7ol1zxu1tc8zNHqXercfDfQIOZm9fR815Cpt5PnVqsr1F51wI9QnzU63xZ1o/rdPPmt6enV6sXqHPVqdXOCe1rtrg5W7zNI+m712Ir+cer4POiqfHeJSVe1Raemwnm7xD3mD1E/Z3wIjcsTdlZnqO8bFeNB9c30zgVG2euYa69QJ+9G90lG+99bfdIoo5PU4w362xHePxl1slMab6tV72KUxDvzlAMT8G0ZohXq39VX1bNzzxij9K1Qb9lhdGe931B/kR6/zCwY9YvuytCsMlj+gbr5SemhqkyuzE8xau4MP865JvWNuj0b1YuqDkgvH2GkURfakly01Cg7Cw0+qyXxkjojq9Lw+vT2AUY+DlF/otYq1Ixc35re2V7R8aTRg2KUv7+ou3x/14PsUBn3NG51S0XpG0Z9PcOPKWSS0SKNUo9Rv2Mmt/G5WpPF6pHGra7Jv410OVsdaz217AbkAPX3ubkm240belCuudT4Rp5p/DyC2lf9mfq1iq5eFe8/lu+K0YrVp0uret4nAkwlB6vzjI/1PxrlrTp/oNHbzTJI92T1qAT+BfW49MhMg6JUp7ehY5a6Tl2jjmVvitF9fxo5Yq8CaAfAkzLMnySt6uz/1k6bPx59CpCNxGfoSKA30IPoH7cQXdArwCOllFX/i53P5P9a/gNkKpsCMFRuFAAAAABJRU5ErkJggg==)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-github-repositories.html#tech-docs-github-pages-publisher) -This repository creates a Docker image and publishes the image to DockerHub. +This repository publishes a utility container for previewing and packaging [GOV.UK's Technical Documentation Template](https://github.com/alphagov/tech-docs-template). -The Docker image is pulled by other repository CI/CD, uses the container with their source code and call the scripts with the container to create documentation websites that meet government technical documents. The data created, ie html website, is then pushed to GH Pages by the repository CI/CD. +## ⚠️ Breaking Changes -The contents of the Docker image will compile embedded ruby and markdown files, ie .html.md.erb, into HTML and assets using the GOV.UK [Technical Documentation Template](https://tdt-documentation.london.cloudapps.digital/) / [Source code](https://github.com/alphagov/tech-docs-template). +### v4 -There are three scripts within the Docker image, that use the Middleman gem to either build or serve the data: +The container is now hosted on GitHub Container Registry. -- [preview.sh](scripts/preview.sh) - serve the compiled HTML and assets on a localhost port - useful for previewing the site locally -- [deploy.sh](scripts/deploy.sh) - compiles the source code, places the HTML into the ./docs folder, tests the **internal links only** using htmlproofer and and creates a .tar artifact file that other GH Actions will serve to GitHub Pages. -- [check-url-links.sh](scripts/check-url-links.sh) - compiles the source code, places the HTML into the ./docs folder, and tests **internal and external URL links** using htmlproofer. +The testing framework is now [Lychee.](https://github.com/lycheeverse/lychee) -This image is used by the [MoJ Template Documentation Site](https://github.com/ministryofjustice/template-documentation-site) repository for MOJ technical documentation that gets published to GitHub Pages. +The scripts have moved: -## Breaking Change in v3 +- `/scripts/deploy.sh` is now `/usr/local/bin/package` + +- `/scripts/preview.sh` is now `/usr/local/bin/preview` + +### v3 The scripts in the Docker container have changed. @@ -35,178 +37,55 @@ You can override the `check_interal_hash` argument with `scripts/deploy.sh false [Optional]: Use the `url-check` job within `.github/workflows/publish-gh-pages.yml` to check the URLs are correct post deployment. Private and internal Github repository URLs and other URLs that create false errors can be listed and skipped within this job. -## Breaking Change in v2 +### v2 If you have a branch called gh-pages already rename it to gh-pages-old. In repository settings, go to Pages, copy the 'Custom domain' value, for 'Build and deployment' 'Source' change to the option 'GitHubs Actions'. Apply the yml code below to your CI Actions. If all is working you can remove the gh-pages-old branch. You may need to manually run the below workflow once it is merged into main. -## How to use tool in GH Action - -Example of using tech-docs-github-pages-publisher. Add the following code to `.github/workflows/publish-gh-pages.yml` in your repository. - -``` -name: Publish gh-pages - -on: - workflow_dispatch: - push: - branches: - - "main" - paths-ignore: - - "docs/**" - -# GITHUB_TOKEN permissions to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow one concurrent deployment -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - container: - image: ministryofjustice/tech-docs-github-pages-publisher:v3 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Compile Markdown to HTML and create artifact - run: /scripts/deploy.sh - - name: Upload artifact to be published - uses: actions/upload-artifact@v3 - with: - name: github-pages - path: artifact.tar - retention-days: 1 - - deploy: - needs: build - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - name: Setup Pages - uses: actions/configure-pages@v2 - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 - - url-check: - needs: deploy - runs-on: ubuntu-latest - steps: - - name: Download a Build Artifact from build - uses: actions/download-artifact@v3 - with: - name: github-pages - path: github-pages - - name: Unpack files and check URL links - run: | - cd github-pages - tar -xvf artifact.tar - npm install linkinator - npx linkinator . --recurse --markdown \ - # --skip https://github.com/ministryofjustice/some-private-repo \ -``` - -Create a `.github/workflows/check-links.yml` file that uses `scripts/check-url-links.sh`. - -``` -name: Check for broken links - -on: - workflow_dispatch: - pull_request: - paths: - - "source/**" - -jobs: - check_links: - runs-on: ubuntu-latest - container: - image: ministryofjustice/tech-docs-github-pages-publisher:v3 - steps: - - uses: actions/checkout@v3 - - name: htmlproofer - run: /scripts/check-url-links.sh -``` - -## Local development with another MoJ Documentation repository: - -This assumes you have Ruby and Bundler already installed on your local machine. See the [installation](https://tdt-documentation.london.cloudapps.digital/create_project/get_started/#get-started) setup. - -Copy the `config.rb` file, `Gemfile` and `Gemfile.lock` from this repository to the checked out repository folder that contains the documentation data. - -``` -gem install middleman - -bundle exec middleman build - -bundle exec middleman serve -``` +## Usage -Open a browser at http://127.0.0.1:4567/ +### GitHub Actions -## Locally in Docker +Examples of how to use the container can be found below: -To run the Docker image locally for development, build the image then run the container from the repository containing the documentation data: +- [`build-test.yml`](examples/github-actions/build-test.yml) -Build the Docker image: +- [`publish.yml`](examples/github-actions/publish.yml) -``` -docker build -t gh-action -f ./Dockerfile . -``` +### Locally -Start the Docker container: +To preview locally, you will need Docker, then you can run: -``` -docker run -it --rm -p 4567:4567 --name ghaction gh-action sh -``` - -In a seperate terminal copy the webpage config and source files: - -``` -docker cp config ghaction:/app/ && docker cp source ghaction:/app/ -``` - -Inside the Docker container run the server locally: - -``` -../scripts/preview.sh -``` - -Open a browser at http://127.0.0.1:4567/ - -Inside the Docker container run the html-proofer tests locally before creating a PR: - -``` -../scripts/deploy.sh +```bash +docker run -it --rm \ + --name tech-docs-github-pages-publisher \ + --publish 4567:4567 \ + --volume $(pwd)/config:/app/config \ + --volume $(pwd)/source:/app/source \ + ministryofjustice/tech-docs-github-pages-publisher:v4.0.0 /usr/local/bin/preview ``` -or +## Updating -``` -../scripts/check-url-links.sh -``` +Dependabot _should_ take care of updating dependencies in [`Gemfile`](src/opt/publisher/Gemfile) and [`Gemfile.lock`](src/opt/publisher/Gemfile.lock). -Alternatively use the [makefile](https://github.com/ministryofjustice/technical-guidance/blob/main/makefile) from the technical-guidance repository to run the Docker container locally using the `make preview`, `make deploy` or `make check` commands. +However if you need to update manually, you can do the following: -## CI/CD +1. Build the image -A [GitHub Action](.github/workflows/docker-hub.yml) publishes this repository Docker image to DockerHub. + ```bash + docker build --file Dockerfile --tag ministryofjustice/tech-docs-github-pages-publisher:local . + ``` -## Updating +1. Extract `Gemfile.lock` -The [govuk_tech_docs](https://rubygems.org/gems/govuk_tech_docs) gem is within the Gemfile. + ```bash + docker run -it --rm ministryofjustice/tech-docs-github-pages-publisher:local -Either Dependabot will automatically update the gem or a new PR with the gem updated is required. + cat /opt/publisher/Gemfile.lock + ``` -The Gems in the `Gemfile` are fixed for various reasons. This prevents incrementing the versions. +1. Replace [`Gemfile.lock`](src/opt/publisher/Gemfile.lock) -## Markdown in html +## Releasing -Markdown syntax used within the compiled down html files can be found [here](https://daringfireball.net/projects/markdown/) and here [kramdown](https://kramdown.gettalong.org/syntax.html). +To create a new release, follow [GitHub's procedure](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release) diff --git a/bin/package b/bin/package new file mode 100755 index 0000000..b363627 --- /dev/null +++ b/bin/package @@ -0,0 +1,10 @@ +#!/bin/sh + +# Restore config.rb, Gemfile and Gemfile.lock +cp /opt/publisher/* . + +# Compile the site +bundle exec middleman build --build-dir docs --relative-links --verbose + +# Create the artifact +tar --dereference --directory docs -cvf artifact.tar --exclude=.git --exclude=.github . diff --git a/bin/preview b/bin/preview new file mode 100755 index 0000000..9cb9bce --- /dev/null +++ b/bin/preview @@ -0,0 +1,7 @@ +#!/bin/sh + +# Restore config.rb, Gemfile and Gemfile.lock +cp /opt/publisher/* . + +# Run the site +bundle exec middleman serve diff --git a/config.rb b/config.rb deleted file mode 100644 index 9d009d7..0000000 --- a/config.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "govuk_tech_docs" - -GovukTechDocs.configure(self) - -activate :relative_assets - -# Do not add the 'set :relative_links, true' it will break the current MoJ GH Doc websites diff --git a/examples/github-actions/build-test.yml b/examples/github-actions/build-test.yml new file mode 100644 index 0000000..0a91671 --- /dev/null +++ b/examples/github-actions/build-test.yml @@ -0,0 +1,34 @@ +--- +name: Build and Test + +on: + pull_request: + branches: + - main + +permissions: {} + +jobs: + build: + name: Build + runs-on: ubuntu-latest + container: + image: ministryofjustice/tech-docs-github-pages-publisher:v4.0.0 + permissions: + contents: read + steps: + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Build + id: build + run: | + /usr/local/bin/package + + - name: Lychee + id: lychee + uses: lycheeverse/lychee-action@c053181aa0c3d17606addfe97a9075a32723548a # v1.9.3 + with: + args: --verbose --no-progress './**/*.md' './**/*.html' './**/*.erb' --accept 403,200,429 + fail: true diff --git a/examples/github-actions/publish.yml b/examples/github-actions/publish.yml new file mode 100644 index 0000000..c459033 --- /dev/null +++ b/examples/github-actions/publish.yml @@ -0,0 +1,61 @@ +--- +name: Publish + +on: + push: + branches: + - main + +permissions: {} + +concurrency: + group: github-pages + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-latest + container: + image: ministryofjustice/tech-docs-github-pages-publisher:v4.0.0 + permissions: + contents: read + steps: + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Build + id: build + run: | + /usr/local/bin/package + + - name: Upload Artifact + id: upload_artifact + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + with: + name: github-pages + path: artifact.tar + retention-days: 1 + overwrite: true + + publish: + needs: build + name: Publish + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.configure_pages.outputs.base_url }} + permissions: + contents: read + id-token: write + pages: write + steps: + - name: Configure Pages + id: configure_pages + uses: actions/configure-pages@1f0c5cde4bc74cd7e1254d0cb4de8d49e9068c7d # v4.0.0 + + - name: Deploy to GitHub Pages + id: deploy_pages + uses: actions/deploy-pages@decdde0ac072f6dcbe43649d82d9c635fff5b4e4 # v4.0.4 + \ No newline at end of file diff --git a/scripts/check-url-links.sh b/scripts/check-url-links.sh deleted file mode 100755 index d0f8815..0000000 --- a/scripts/check-url-links.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -x -set -euo pipefail - -# Restore the stashed config.rb Gemfile and Gemfile.lock -cp /stashed-files/* . - -# Compile source markdown files into HTML in the `/docs` directory -bundle exec middleman build --build-dir docs --relative-links --verbose - -# Check all URLs -htmlproofer --log-level debug --allow-missing-href true --typhoeus '{"connecttimeout": 10, "timeout": 30, "accept_encoding": "zstd,br,gzip,deflate" }' ./docs diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100755 index 52eb57f..0000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -x -set -euo pipefail - -CHECK_INTERNAL_HASH=${1:-true} - -# Restore the stashed config.rb Gemfile and Gemfile.lock -cp /stashed-files/* . - -# Compile source markdown files into HTML in the `/docs` directory -bundle exec middleman build --build-dir docs --relative-links --verbose - -touch docs/.nojekyll - -# Internal link check only within the docs folder -htmlproofer --log-level debug --allow-missing-href true --disable_external true --check-internal-hash "$CHECK_INTERNAL_HASH" ./docs - -tar --dereference --directory docs -cvf artifact.tar --exclude=.git --exclude=.github . diff --git a/scripts/preview.sh b/scripts/preview.sh deleted file mode 100755 index cb27300..0000000 --- a/scripts/preview.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# Allow documentation sites to preview what the site will look like when published. - -set -euo pipefail - -# Restore the stashed config.rb Gemfile and Gemfile.lock -cp /stashed-files/* . - -bundle exec middleman serve diff --git a/src/opt/publisher/Gemfile b/src/opt/publisher/Gemfile new file mode 100644 index 0000000..e89f204 --- /dev/null +++ b/src/opt/publisher/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem 'govuk_tech_docs', '3.5.0' diff --git a/Gemfile.lock b/src/opt/publisher/Gemfile.lock similarity index 85% rename from Gemfile.lock rename to src/opt/publisher/Gemfile.lock index 4bbd70e..565e13a 100644 --- a/Gemfile.lock +++ b/src/opt/publisher/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (7.0.8) + activesupport (7.0.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -32,19 +32,17 @@ GEM sass (>= 3.2, < 3.5) concurrent-ruby (1.2.3) contracts (0.16.1) - dotenv (2.8.1) + dotenv (3.0.2) em-websocket (0.5.3) eventmachine (>= 0.12.9) http_parser.rb (~> 0) erubis (2.7.0) - ethon (0.16.0) - ffi (>= 1.15.0) eventmachine (1.2.7) execjs (2.9.1) fast_blank (1.0.1) fastimage (2.3.0) ffi (1.16.3) - govuk_tech_docs (3.4.0) + govuk_tech_docs (3.5.0) autoprefixer-rails (~> 10.2) chronic (~> 0.10.2) haml (< 6.0.0) @@ -64,15 +62,6 @@ GEM hamster (3.0.0) concurrent-ruby (~> 1.0) hashie (3.6.0) - html-proofer (4.4.3) - addressable (~> 2.3) - mercenary (~> 0.3) - nokogiri (~> 1.13) - parallel (~> 1.10) - rainbow (~> 3.0) - typhoeus (~> 1.3) - yell (~> 2.0) - zeitwerk (~> 2.5) http_parser.rb (0.8.0) i18n (1.6.0) concurrent-ruby (~> 1.0) @@ -82,7 +71,6 @@ GEM rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) memoist (0.16.2) - mercenary (0.4.0) middleman (4.5.1) coffee-script (~> 2.2) haml (>= 4.0.5) @@ -136,11 +124,19 @@ GEM middleman-syntax (3.2.0) middleman-core (>= 3.2) rouge (~> 3.2) - mini_portile2 (2.8.5) - minitest (5.21.2) + minitest (5.22.2) multi_json (1.15.0) - nokogiri (1.15.5) - mini_portile2 (~> 2.8.2) + nokogiri (1.16.2-aarch64-linux) + racc (~> 1.4) + nokogiri (1.16.2-arm-linux) + racc (~> 1.4) + nokogiri (1.16.2-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.2-x86-linux) + racc (~> 1.4) + nokogiri (1.16.2-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) openapi3_parser (0.9.2) commonmarker (~> 0.17) @@ -153,10 +149,9 @@ GEM parslet (2.0.0) public_suffix (5.0.4) racc (1.7.3) - rack (2.2.8) + rack (2.2.8.1) rack-livereload (0.3.17) rack - rainbow (3.1.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) @@ -175,26 +170,23 @@ GEM tilt (2.0.11) toml (0.3.0) parslet (>= 1.8.0, < 3.0.0) - typhoeus (1.4.1) - ethon (>= 0.9.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uglifier (3.2.0) execjs (>= 0.3.0, < 3) webrick (1.8.1) - yell (2.2.2) - zeitwerk (2.6.12) PLATFORMS - ruby + aarch64-linux + arm-linux + arm64-darwin + x86-linux + x86_64-darwin + x86_64-linux + x86_64-linux-musl DEPENDENCIES - govuk_tech_docs - haml (= 5.2.2) - html-proofer (= 4.4.3) - -RUBY VERSION - ruby 2.7.6p219 + govuk_tech_docs (= 3.5.0) BUNDLED WITH - 2.4.22 + 2.5.6 diff --git a/src/opt/publisher/config.rb b/src/opt/publisher/config.rb new file mode 100644 index 0000000..8eeecee --- /dev/null +++ b/src/opt/publisher/config.rb @@ -0,0 +1,3 @@ +require "govuk_tech_docs" + +GovukTechDocs.configure(self) diff --git a/test/config/tech-docs.yml b/test/config/tech-docs.yml new file mode 100644 index 0000000..3d2d359 --- /dev/null +++ b/test/config/tech-docs.yml @@ -0,0 +1,18 @@ +--- +# See the available options: https://tdt-documentation.london.cloudapps.digital/configure_project/global_configuration/#configure-your-documentation-site + +host: https://ministryofjustice.github.io/tech-docs-github-pages-publisher +show_govuk_logo: false +service_name: Tech Docs GitHub Pages Publisher +service_link: / +phase: test +enable_search: true +collapsible_nav: true +max_toc_heading_level: 3 +prevent_indexing: true +show_contribution_banner: true +github_repo: ministryofjustice/tech-docs-github-pages-publisher +github_branch: main +full_service_name: Tech Docs GitHub Pages Publisher +show_expiry: true +show_review_banner: true diff --git a/test/source/index.html.md.erb b/test/source/index.html.md.erb new file mode 100644 index 0000000..0cd0707 --- /dev/null +++ b/test/source/index.html.md.erb @@ -0,0 +1,11 @@ +--- +owner_slack: "#operations-engineering" +title: Tech Docs GitHub Pages Publisher +last_reviewed_on: 2024-02-21 +review_in: 2 weeks +weight: 0 +--- + +# <%= current_page.data.title %> + +This is a test diff --git a/test/source/javascripts/application.js b/test/source/javascripts/application.js new file mode 100644 index 0000000..8a5d80b --- /dev/null +++ b/test/source/javascripts/application.js @@ -0,0 +1 @@ +//= require govuk_tech_docs diff --git a/test/source/stylesheets/print.css.scss b/test/source/stylesheets/print.css.scss new file mode 100644 index 0000000..82b181c --- /dev/null +++ b/test/source/stylesheets/print.css.scss @@ -0,0 +1,3 @@ +$is-print: true; + +@import "govuk_tech_docs"; diff --git a/test/source/stylesheets/screen-old-ie.css.scss b/test/source/stylesheets/screen-old-ie.css.scss new file mode 100644 index 0000000..da90cca --- /dev/null +++ b/test/source/stylesheets/screen-old-ie.css.scss @@ -0,0 +1,4 @@ +$is-ie: true; +$ie-version: 8; + +@import "govuk_tech_docs"; diff --git a/test/source/stylesheets/screen.css.scss b/test/source/stylesheets/screen.css.scss new file mode 100644 index 0000000..b6b143a --- /dev/null +++ b/test/source/stylesheets/screen.css.scss @@ -0,0 +1 @@ +@import "govuk_tech_docs"; \ No newline at end of file