-
Notifications
You must be signed in to change notification settings - Fork 11
58 lines (57 loc) · 2.16 KB
/
sync_docs.yaml
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
on:
workflow_call:
inputs:
reviewers:
description: Comma separated list of GitHub usernames to request to review pull request (e.g. "canonical/data-platform-engineers,octocat")
required: false
type: string
jobs:
sync-docs:
name: Sync docs from Discourse
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Get workflow version
id: workflow-version
uses: canonical/get-workflow-version-action@v1
with:
repository-name: canonical/data-platform-workflows
file-name: sync_docs.yaml
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install CLI
run: pipx install git+https://github.com/canonical/data-platform-workflows@'${{ steps.workflow-version.outputs.sha }}'#subdirectory=python/cli
- name: Checkout
uses: actions/checkout@v4
- name: Update Discourse docs
run: sync-docs
- name: Push `sync-docs` branch & create pull request
run: |
git checkout -b sync-docs
git add docs/
# Check if changes staged
if git diff --cached --quiet
then
echo 'No changes to docs/ from default git branch'
# Delete branch on GitHub if it exists
# (GitHub will automatically close PR if it exists)
if git ls-remote --exit-code origin sync-docs
then
git push origin --delete sync-docs
fi
exit 0
fi
git config user.name "GitHub Actions"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "Sync docs from Discourse"
git push origin sync-docs -f
# Create pull request
# Capture output in variable so that step fails if `gh pr list` exits with non-zero code
prs=$(gh pr list --head sync-docs --state open --json number)
if [[ $prs != "[]" ]]
then
echo Open pull request already exists
exit 0
fi
gh pr create --head sync-docs --title "Sync docs from Discourse" --body "Sync charm docs from https://discourse.charmhub.io" --reviewer '${{ inputs.reviewers }}'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}