-
Notifications
You must be signed in to change notification settings - Fork 32
119 lines (107 loc) 路 4.18 KB
/
Copy pathbuildDocs.yml
File metadata and controls
119 lines (107 loc) 路 4.18 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
110
111
112
113
114
115
116
117
118
119
name: Build Documentation & Generate Reports
on: [push, workflow_dispatch]
jobs:
build-documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources"
module-name: Twift
output: "Documentation"
- name: Upload Documentation to Wiki
# Only run on the main branch
if: github.ref == 'refs/heads/main'
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "Documentation"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
generate-coverage-report:
runs-on: ubuntu-latest
outputs:
body: ${{ steps.coverage-report.outputs.body }}
container: docker://swiftdoc/swift-doc:latest
steps:
- uses: actions/checkout@v1
- name: Generate coverage report
id: coverage-report
run: |
body="$(swift-doc coverage "./Sources" --minimum-access-level public | sed '/^\s*$/q' | head -n 1000)"
body="$(echo "$body" | perl -p -e 's/%/%25/g' | perl -p -e 's/\n/%0A/gm' | perl -p -e 's/\r/%0D/gm')"
echo "::set-output name=body::$body"
comment-on-commit:
runs-on: ubuntu-latest
needs: generate-coverage-report
steps:
- name: Transform report into markdown table
id: md-table
run: |
mdtable="${{ needs.generate-coverage-report.outputs.body }}"
mdtable="$(echo "$mdtable" | perl -p -e 's/^[\s-]*([a-zA-Z+.]+)\s*([0-9.]+) ?%/|$1|$2%|\r/g')"
mdtable="$(echo "$mdtable" | perl -p -e 's/%/%25/g' | perl -p -e 's/\n/%0A/gm' | perl -p -e 's/\r/%0D/gm')"
mdtable="<details>%0A<summary>View documentation coverage after this change</summary>%0A%0A|Filename|Coverage|%0A|---|---|%0A$(echo "$mdtable")%0A</details>%0A"
mdtable="${mdtable//$'\n'/%0A}"
mdtable="${mdtable//$'\r'/%0D}"
echo "::set-output name=table::$mdtable"
- name: Comment on commit
uses: peter-evans/commit-comment@v1
with:
body: ${{ steps.md-table.outputs.table }}
update-coverage-badge:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: generate-coverage-report
env:
coverage_report: ${{ needs.generate-coverage-report.outputs.body }}
steps:
- uses: actions/checkout@v1
- name: Extract total percentage from report
id: coverage-percent
run: |
percent="$(echo "$coverage_report" | grep -Eio '[0-9]+' | head -n 1)"
echo "::set-output name=percent::$percent"
- name: Checkout `badges` branch
run: |
git checkout badges
- name: Good coverage badge
if: ${{ steps.coverage-percent.outputs.percent >= 80 }}
uses: emibcn/badge-action@v1.2.1
with:
label: "Docs Coverage"
status: "${{steps.coverage-percent.outputs.percent}}%"
color: "34c759"
path: ".github/badges/coverage.svg"
- name: Okay coverage badge
if:
${{ steps.coverage-percent.outputs.percent >= 50 &&
steps.coverage-percent.outputs.percent < 80 }}
uses: emibcn/badge-action@v1.2.1
with:
label: "Docs Coverage"
status: "${{steps.coverage-percent.outputs.percent}}%"
color: "f59500"
path: ".github/badges/coverage.svg"
- name: Poor coverage badge
if: ${{ steps.coverage-percent.outputs.percent < 50 }}
uses: emibcn/badge-action@v1.2.1
with:
label: "Docs Coverage"
status: "${{steps.coverage-percent.outputs.percent}}%"
color: "ff3b30"
path: ".github/badges/coverage.svg"
- name: Commit badge
continue-on-error: true
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ".github/badges/coverage.svg"
git commit -m "Add/Update badge"
- name: Push badge commit
uses: ad-m/github-push-action@master
if: ${{ success() }}
with:
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
branch: badges