-
Notifications
You must be signed in to change notification settings - Fork 18
136 lines (127 loc) · 5.72 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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.
#
# This is always performed (even on failure, and even with no code changes), as a mechanism to
# surface failures to the reviewer. This workflow is usually triggered by automation in the
# background after a release, and it is easy for the release manager to forget to follow up
# about the docs (if there's a silent failure).
- name: Commit changes
if: always()
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 --allow-empty
git push -u origin "automation/sync-${{ inputs.version }}"
working-directory: pantsbuild.org
- name: Prepare PR text
if: always()
run: |
touch title-prefix.md
echo "Docs from https://github.com/pantsbuild/pants/releases/tag/release_${{ inputs.version }}" > body.md
# When the job is failing, add extra info to the PR body:
- name: Append failure info
if: failure()
run: |
echo "[FAILURE] " >> title-prefix.md
{
echo
# (would be nice if there was a way to link to this job directly, but the required ID doesn't seem to be available via the context objects)
echo "The sync_docs job failed part way through and may need debugging: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo
echo "Note: to retry the job, first close this PR and delete its branch."
} >> body.md
- name: Make a PR
if: always()
run: gh pr create --title "$(cat ../title-prefix.md)Update docs site for version ${{ inputs.version }}" --body-file=../body.md --reviewer "${{ inputs.reviewer || github.actor }}" --label 'automation:sync-docs'
env:
GH_TOKEN: ${{ secrets.WORKER_PANTS_PR_PAT }}
working-directory: pantsbuild.org