-
Notifications
You must be signed in to change notification settings - Fork 18
108 lines (100 loc) · 4.48 KB
/
sync_docs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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