Sync the Docs: version 2.18.1 #30
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. | |
# NB: We run the command initially twice, since the first run might put extraneous crap on stdout. | |
run: | | |
touch pants.toml | |
PANTS_VERSION="${{ inputs.version }}" pants help-all > /dev/null | |
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 | |
# 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 "pantsbuild.org/$DESTINATION_DIR" ]; then | |
DESTINATION_DIR="docs" | |
fi | |
echo "DESTINATION_DIR=$(echo "$DESTINATION_DIR")" | tee -a "${GITHUB_OUTPUT}" | |
- 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: 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 | |
- 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 "pantsbuild.org/${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}" | |
- run: npm run format -- "${{ steps.get-destination-dir.outputs.DESTINATION_DIR }}" | |
working-directory: pantsbuild.org | |
# Commit and create a PR | |
- name: Commit changes | |
run: | | |
git config --local user.email "[email protected]" | |
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 }}" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
working-directory: pantsbuild.org |