2023-08-16 05:31:01 -04:00
|
|
|
name: pr
|
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
preview:
|
|
|
|
runs-on: docker
|
|
|
|
container:
|
|
|
|
image: node:20
|
|
|
|
steps:
|
|
|
|
- uses: https://code.forgejo.org/actions/checkout@v3
|
2023-08-16 11:34:40 -04:00
|
|
|
- name: lint
|
|
|
|
run: |
|
|
|
|
corepack enable
|
|
|
|
pnpm install --frozen-lockfile
|
|
|
|
pnpm run lint:remark
|
|
|
|
pnpm run lint:prettier
|
2023-08-16 05:31:01 -04:00
|
|
|
- name: get forgejo.org and move the docs
|
|
|
|
run: |
|
|
|
|
git clone --recursive --depth 1 https://codeberg.org/forgejo/website/ /tmp/website
|
2023-08-16 06:32:04 -04:00
|
|
|
apt-get update -qq && apt-get install -qq -y rsync
|
|
|
|
rsync -av --delete ./ /tmp/website/forgejo-docs/${{ env.GITHUB_BASE_REF }}/
|
2023-08-16 05:31:01 -04:00
|
|
|
- name: install
|
|
|
|
run: |
|
|
|
|
cd /tmp/website
|
|
|
|
corepack enable
|
|
|
|
pnpm install --frozen-lockfile
|
|
|
|
- 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
|
2023-08-17 13:18:40 -04:00
|
|
|
remote_branch_present=$(git show-branch refs/remotes/origin/$branch 2>/dev/null || true)
|
2023-08-16 05:31:01 -04:00
|
|
|
git push --force origin $branch
|
2023-08-17 13:18:40 -04:00
|
|
|
|
|
|
|
# Add PR comment with preview links on PR which were not already deployed
|
|
|
|
if [ ! "$remote_branch_present" ]; then
|
|
|
|
echo -n '{"body": "Preview ready: https://forgejo.codeberg.page/@'"$branch"'/' > comment.json
|
|
|
|
|
|
|
|
# Add link to 5 first pages with more than 100 changes
|
|
|
|
# awk is actually mawk, which does not support regex interval {n,m}
|
|
|
|
git diff --stat origin/main | awk '/\.html *\| *[0-9][0-9][0-9]+ [+-]*$/ { print $3, $1 }' | sort -rn | head -n5 | cut -d" " -f2 | sed 's/index\.html//' | sed 's#^#\\\\nhttps://forgejo.codeberg.page/@'"$branch"'/#' | tr -d '\n' >> comment.json
|
|
|
|
echo '"}' >> comment.json
|
|
|
|
|
|
|
|
# Post PR comment
|
|
|
|
curl -d @comment.json -H "Content-Type: application/json" -X POST "https://forgejo-website:${{ secrets.WEBSITETOKEN }}@codeberg.org/api/v1/repos/forgejo/docs/issues/${{ env.GITHUB_REF_NAME }}/comments"
|
|
|
|
fi
|