From fc108d2064ec656858a372ed01f62728caf4884a Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 16 Aug 2023 09:31:01 +0000 Subject: [PATCH] add CI to preview PRs (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: - [x] clone from website instead of caesar - [x] skip the proof of change commit Preview: https://forgejo.codeberg.page/@docs_pull_5/ This is a simplistic approach to get started with previews. It copies the website, moves the docs under `/forgejo-docs/{{ base branch }}`, create the website and publishes it for preview. No doubt the actual workflow will be different but that needs to be decided. * Added a WEBSITETOKEN secret created from the forgejo-website user. It is a token with write access to repositories. https://codeberg.org/forgejo/docs/settings/actions/secrets. Contrary to woodpecker it is not in an environment variable but will be replaced when inserting `${{ secrets.WEBSITETOKEN }}` somewhere * In the environment the variable was replaced CI_COMMIT_PULL_REQUEST → `${{ env.GITHUB_REF_NAME }}` * The preview is published at https://forgejo.codeberg.page/@docs_pull_N/ instead of https://forgejo.codeberg.page/@pull_N/ * The `$$` were replaced with `$` in the script because Forgejo Actions does not interpret `$` and therefore does not need escaping them to `$$` Reviewed-on: https://codeberg.org/forgejo/docs/pulls/5 Reviewed-by: Loïc Dachary Reviewed-by: Caesar Schinas Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- .forgejo/workflows/pr.yml | 47 +++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 48 insertions(+) create mode 100644 .forgejo/workflows/pr.yml create mode 100644 .gitignore diff --git a/.forgejo/workflows/pr.yml b/.forgejo/workflows/pr.yml new file mode 100644 index 00000000..fe1de2c0 --- /dev/null +++ b/.forgejo/workflows/pr.yml @@ -0,0 +1,47 @@ +name: pr + +on: + pull_request: + +jobs: + preview: + runs-on: docker + container: + image: node:20 + steps: + - uses: https://code.forgejo.org/actions/checkout@v3 + - name: get forgejo.org and move the docs + run: | + git clone --recursive --depth 1 https://codeberg.org/forgejo/website/ /tmp/website + rm -fr /tmp/website/forgejo-docs/${{ env.GITHUB_BASE_REF }} + mkdir -p /tmp/website/forgejo-docs/${{ env.GITHUB_BASE_REF }} + cp -a * /tmp/website/forgejo-docs/${{ env.GITHUB_BASE_REF }} + - name: install + run: | + cd /tmp/website + corepack enable + pnpm install --frozen-lockfile + - name: lint:eslint + run: | + cd /tmp/website + corepack enable + pnpm run format-ci + pnpm run lint:eslint + - name: preview + if: ${{ secrets.WEBSITETOKEN != '' }} + run: | + cd /tmp/website + colon=':' + branch=docs_pull_${{ env.GITHUB_REF_NAME }} + sed -i.orig -e "s|origin$colon '.*|origin$colon 'https$colon//forgejo.codeberg.page',|" -e "s|basePathname$colon '/'|basePathname$colon '/@$branch//'|" src/config.mjs + cat src/config.mjs + corepack enable + pnpm run build + git clone https://forgejo-website:${{ secrets.WEBSITETOKEN }}@codeberg.org/forgejo/pages /tmp/pages + git -C /tmp/pages switch -C $branch + mv /tmp/pages/.git dist + cd dist + git config user.email "ci@forgejo.org" ; git config user.name "forgejo-website" + git add . + git diff-index --quiet HEAD || git commit -m 'publish' -a + git push --force origin $branch diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b25c15b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~