From 801854b75a28a6d9d21678e8d5e9fa8f8f1e3953 Mon Sep 17 00:00:00 2001 From: Antoine BERNIER Date: Fri, 9 Aug 2024 23:21:10 +0200 Subject: [PATCH] reusable + caller --- .github/workflows/build.yml | 44 ++++++++++++++++++++++++++++++++++++ .github/workflows/docker.yml | 18 +++------------ .github/workflows/docs.yml | 29 ++++++++++++++++++++++++ docs/index.mdx | 3 +++ next.config.mjs | 2 ++ readme.md | 20 +++++++++++----- 6 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/docs.yml create mode 100644 docs/index.mdx diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..2341f67e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,44 @@ +name: Reusable pmndrs/docs workflow + +on: + workflow_call: + inputs: + mdx: + required: true + type: string + libname: + required: true + type: string + +jobs: + build-job: + runs-on: ubuntu-latest + + # container: + # image: ghcr.io/pmndrs/playwright:main + # credentials: + # username: ${{ github.actor }} + # password: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + - id: configurepages + uses: actions/configure-pages@v5 + - run: | + docker run --rm --init \ + -v "$MDX":/app/docs \ + -e BASE_PATH \ + -e DIST_DIR=docs/out \ + -e MDX \ + -e NEXT_PUBLIC_NAME \ + ghcr.io/pmndrs/docs:app-router yarn build + env: + BASE_PATH: ${{ steps.configurepages.outputs.base_path }} + MDX: ${{ inputs.mdx }} + NEXT_PUBLIC_LIBNAME: ${{ inputs.mdx }} + + - run: ls -al ${{ inputs.mdx }} + + - uses: actions/upload-pages-artifact@v3 + with: + path: ${{ inputs.mdx }}/out diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 30f6087f..f5e0b02a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,5 @@ -name: Create and publish a multi-arch Docker image +# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages +name: Create and publish a Docker image on: push: branches: ['main', 'app-router'] @@ -20,18 +21,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - with: - install: true - - name: Log in to the Container registry uses: docker/login-action@v3 with: @@ -51,13 +40,12 @@ jobs: with: context: . push: true - platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - name: Generate artifact attestation uses: actions/attest-build-provenance@v1 with: - subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} subject-digest: ${{ steps.push.outputs.digest }} push-to-registry: true diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..44b9a30c --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,29 @@ +name: Create and publish a multi-arch Docker image +on: + push: + branches: ['main', 'app-router'] + +jobs: + build: + uses: pmndrs/docs/.github/workflows/build.yml@app-router + with: + mdx: ./docs + libname: 'pmndrs' + + deploy: + needs: build + runs-on: ubuntu-latest + + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + # Deploy to the github-pages environment + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/docs/index.mdx b/docs/index.mdx new file mode 100644 index 00000000..0af6389d --- /dev/null +++ b/docs/index.mdx @@ -0,0 +1,3 @@ +# hello + +this is documentation for @pmndrs/docs diff --git a/next.config.mjs b/next.config.mjs index 1bd740f3..82c602a1 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,3 +1,4 @@ +const basePath = process.env.BASE_PATH || '' const distDir = process.env.DIST_DIR || undefined /** @type {import('next').NextConfig} */ @@ -7,6 +8,7 @@ const nextConfig = { // domains: ['codesandbox.io'], unoptimized: true, }, + basePath, output: 'export', distDir, // async redirects() { diff --git a/readme.md b/readme.md index 2307fa65..07cb80f1 100644 --- a/readme.md +++ b/readme.md @@ -15,12 +15,20 @@ $ MDX=docs NEXT_PUBLIC_LIBNAME="React Three Fiber" yarn build # Docker -``` +```sh $ docker build -t pmndrs-docs . +``` -$ docker run --rm --init -it \ - -v $(pwd)/docs:/app/docs \ - -e DIST_DIR=docs/out \ - -e NEXT_PUBLIC_LIBNAME="React Three Fiber" \ - pmndrs-docs yarn build +```sh +$ export BASE_PATH=/foo; \ + export MDX=./docs; \ + export NEXT_PUBLIC_NAME="pmndrs"; \ + \ + rm -rf "$MDX/out" && docker run --rm --init -it \ + -v "$MDX":/app/docs \ + -e BASE_PATH \ + -e DIST_DIR=docs/out \ + -e MDX \ + -e NEXT_PUBLIC_NAME \ + pmndrs-docs yarn build ```