Sync the Docs: version 2.22.1rc0 #98
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: Sync the Docs | |
run-name: >- | |
Sync the Docs: version ${{ inputs.version }} | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: Pants Version to use (should be the full version, like "2.20.1rc2") | |
required: true | |
type: string | |
reviewer: | |
description: | | |
Who to assign as PR reviewer (default: you) | |
required: false | |
type: string | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
# Generate `help-all.json` | |
- name: Pants on! | |
run: | | |
curl --proto '=https' --tlsv1.2 -fsSL https://static.pantsbuild.org/setup/get-pants.sh | bash | |
echo "$HOME/.local/bin" >> $GITHUB_PATH | |
- name: Generate help JSON | |
# First run `help-all` which will contain the list of every backend in the `name_to_backend_help_info` object, | |
# then run it again with every backend enabled. | |
run: | | |
touch pants.toml | |
PANTS_VERSION="${{ inputs.version }}" pants help-all > help-all.json | |
PANTS_VERSION="${{ inputs.version }}" pants --backend-packages=[$(jq -r '.name_to_backend_help_info | keys_unsorted | map("\"" + . + "\"") | join(",")' help-all.json)] help-all > help-all.json | |
# Checkout both repos | |
- name: Checkout pants repo | |
uses: actions/checkout@v4 | |
with: | |
repository: pantsbuild/pants | |
ref: release_${{ inputs.version }} | |
fetch-depth: 0 | |
path: pants | |
- name: Checkout docs repo | |
uses: actions/checkout@v4 | |
with: | |
repository: pantsbuild/pantsbuild.org | |
fetch-depth: 0 | |
path: pantsbuild.org | |
# Setup `node` and friends | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18" | |
- name: Get yarn cache | |
id: yarn-cache | |
run: echo "YARN_CACHE_DIR=$(yarn cache dir)" >> "${GITHUB_OUTPUT}" | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ${{ steps.yarn-cache.outputs.YARN_CACHE_DIR }} | |
key: ${{ runner.os }}-website-${{ hashFiles('pantsbuild.org/**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-website- | |
- run: yarn install --frozen-lockfile | |
working-directory: pantsbuild.org | |
# Calculate destination | |
- name: Calculate destination | |
id: get-destination-dir | |
run: | | |
BASE_VERSION=$(echo "${{ inputs.version }}" | sed -E 's/^([0-9]+)\.([0-9]+)\.\w+.*/\1.\2/') | |
DESTINATION_DIR="versioned_docs/version-$BASE_VERSION" | |
if [ ! -d "$DESTINATION_DIR" ]; then | |
if [[ "${{ inputs.version }}" =~ .*\.0a0$ ]]; then | |
# a0 => we've cut a new branch from `main`, so make a new version | |
npm run docusaurus docs:version $BASE_VERSION | |
else | |
DESTINATION_DIR="docs" | |
fi | |
fi | |
echo "DESTINATION_DIR=$(echo "$DESTINATION_DIR")" | tee -a "${GITHUB_OUTPUT}" | |
working-directory: pantsbuild.org | |
- run: | | |
rm -rf "pantsbuild.org/${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}" | |
mkdir -p "pantsbuild.org/${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}/reference" | |
cp help-all.json "pantsbuild.org/${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}/reference" | |
# Generate reference docs | |
- name: Generate reference docs | |
run: npm run generate-reference "${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}" | |
working-directory: pantsbuild.org | |
# Sync the docs repo | |
- run: cp -r pants/docs/docs "pantsbuild.org/${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}" | |
# Commit and create a PR | |
- name: Commit changes | |
run: | | |
git config --local user.email "pantsbuild+github-automation@gmail.com" | |
git config --local user.name "Worker Pants (Pantsbuild GitHub Automation Bot)" | |
git checkout -b "automation/sync-${{ inputs.version }}" | |
git add -A | |
git commit -m "Update docs site for version ${{ inputs.version }}" -a | |
git push -u origin "automation/sync-${{ inputs.version }}" | |
working-directory: pantsbuild.org | |
- name: Make a PR | |
run: gh pr create --title "Update docs site for version ${{ inputs.version }}" --body "Docs from https://github.com/pantsbuild/pants/releases/tag/release_${{ inputs.version }}" --reviewer "${{ inputs.reviewer || github.actor }}" --label 'automation:sync-docs' | |
env: | |
GH_TOKEN: ${{ secrets.WORKER_PANTS_PR_PAT }} | |
working-directory: pantsbuild.org |