-
Notifications
You must be signed in to change notification settings - Fork 3
88 lines (84 loc) · 3.06 KB
/
sync-docs.yml
File metadata and controls
88 lines (84 loc) · 3.06 KB
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
# Uses the org-wide REPO_TOKEN secret (PAT or GitHub App installation token)
# that must have contents:write and pull-requests:write on VirtoCommerce/vc-docs.
# Same secret is used by release.yml and storybook-ci.yml in this repo and by
# deploy.yml in vc-docs. Configure via Settings → Secrets and variables → Actions.
name: sync-docs
on:
release:
types: [published]
workflow_dispatch:
inputs:
target_branch:
description: "vc-docs branch to checkout and open the PR against (defaults to main)"
required: false
default: main
ref_label:
description: "Label used in the auto-PR branch name and title (defaults to a UTC timestamp)"
required: false
default: ""
jobs:
sync:
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.prerelease }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: VirtoCommerce/vc-docs
path: vc-docs
token: ${{ secrets.REPO_TOKEN }}
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.target_branch || 'main' }}
- uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- run: corepack enable
- run: yarn install --immutable
- run: yarn workspace @vc-shell/docs-sync build
- name: Run sync
env:
WORKSPACE_DIR: ${{ github.workspace }}
run: |
yarn workspace @vc-shell/docs-sync exec docs-sync sync \
--target "$WORKSPACE_DIR/vc-docs" \
--report "$WORKSPACE_DIR/sync-report.md"
- name: Open PR
env:
GH_TOKEN: ${{ secrets.REPO_TOKEN }}
EVENT_NAME: ${{ github.event_name }}
INPUT_TARGET_BRANCH: ${{ inputs.target_branch }}
INPUT_REF_LABEL: ${{ inputs.ref_label }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
BASE="$INPUT_TARGET_BRANCH"
LABEL="$INPUT_REF_LABEL"
if [[ -z "$LABEL" ]]; then
LABEL="manual-$(date -u +%Y%m%d-%H%M%S)"
fi
BRANCH="auto/sync-vc-shell-${LABEL}"
TITLE="docs: manual sync from vc-shell (${LABEL})"
else
BASE="main"
LABEL="$RELEASE_TAG"
BRANCH="auto/sync-vc-shell-${LABEL}"
TITLE="docs: sync from vc-shell@${LABEL}"
fi
cd vc-docs
if [[ -z "$(git status --porcelain)" ]]; then
echo "No changes to sync."
exit 0
fi
git checkout -b "$BRANCH"
git config user.email "bot@virto.dev"
git config user.name "vc-shell-docs-bot"
git add .
git commit -m "$TITLE"
git push origin "$BRANCH"
gh pr create \
--base "$BASE" \
--head "$BRANCH" \
--title "$TITLE" \
--body-file "$GITHUB_WORKSPACE/sync-report.md" \
--label auto-generated