-
-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (106 loc) · 3.59 KB
/
Copy pathdocs.yaml
File metadata and controls
109 lines (106 loc) · 3.59 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Update Docs
on:
push:
branches:
- stable
paths:
- 'lib/**'
- 'pubspec.yaml'
- '.github/workflows/docs.yaml'
pull_request:
branches:
- stable
paths:
- 'lib/**'
- 'pubspec.yaml'
- '.github/workflows/docs.yaml'
jobs:
update-docs:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
branch_exists: ${{ steps.update_docs_branch.outputs.branch_exists }}
changes: ${{ steps.update_docs_branch.outputs.changes }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Dart
uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart pub get
- name: Analyze project source
run: dart analyze
- name: Get version from pubspec.yaml
id: get_version
run: |
VERSION=$(grep '^version:' pubspec.yaml | head -n1 | cut -d ' ' -f2)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate docs
run: dart doc
- name: Clean up everything except doc/
run: |
find . -mindepth 1 -maxdepth 1 ! -name 'doc' ! -name '.git' ! -name '.' ! -name '..' -exec rm -rf {} +
- name: Move doc/api/* to root
run: |
shopt -s dotglob
mv doc/api/* .
shopt -u dotglob
- name: Remove doc/api if empty
run: |
rmdir doc/api || true
- name: Create or update docs branch
id: update_docs_branch
env:
VERSION: ${{ steps.get_version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
BRANCH=docs-for-$VERSION
if git ls-remote --exit-code --heads origin "$BRANCH"; then
echo "branch_exists=true" >> $GITHUB_OUTPUT
git fetch origin "$BRANCH"
git clean -fd
git checkout "$BRANCH"
git reset --hard origin/$BRANCH
else
echo "branch_exists=false" >> $GITHUB_OUTPUT
git checkout --orphan "$BRANCH"
git reset --hard
fi
git add .
echo "Files in working directory:"
ls -alR
echo "Files staged for commit:"
git diff --cached --name-status
echo "Files changed (not staged):"
git diff --name-status
echo "Now checking for changes..."
# Compare current files against origin/gh-pages by path
if git diff --cached --quiet origin/gh-pages -- . 2>/dev/null; then
git commit -m "Update docs for $VERSION"
git push -f origin "$BRANCH"
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "changes=false" >> $GITHUB_OUTPUT
fi
create-docs-pr:
needs: [update-docs]
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
if: needs.update-docs.outputs.changes == 'true' && needs.update-docs.outputs.branch_exists == 'false'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create or update PR to gh-pages
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: gh-pages
title: Docs for ${{ needs.update-docs.outputs.version }}
body: "Automated documentation update for version ${{ needs.update-docs.outputs.version }}."
branch: docs-for-${{ needs.update-docs.outputs.version }}