-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (104 loc) · 3.33 KB
/
generate-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
name: Generate action documentation
on:
push:
branches: [trunk]
pull_request:
branches: [trunk]
jobs:
set-env:
name: Set environment variables
runs-on: ubuntu-latest
outputs:
image_name: ${{ steps.set-output.outputs.image_name }}
image_tag: ${{ steps.set-output.outputs.image_tag }}
steps:
- name: Set image tag
id: set-output
run: |
echo 'image_name=ghcr.io/3lvia/core-github-actions-templates/gh-actions-docs' >> $GITHUB_OUTPUT
if [[ '${{ github.event_name }}' == 'push' ]]; then
echo 'image_tag=latest' >> $GITHUB_OUTPUT
else
echo 'image_tag=${{ github.sha }}' >> $GITHUB_OUTPUT
fi
build-docs-image:
name: Build image for gh-actions-docs
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [set-env]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: 'ghcr.io'
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v5
with:
context: '.github/gh-actions-docs'
push: 'true'
tags: '${{ needs.set-env.outputs.image_name }}:${{ needs.set-env.outputs.image_tag }}'
cache-from: 'type=registry,ref=${{ needs.set-env.outputs.image_name }}:latest'
cache-to: 'type=inline'
generate-docs:
name: Generate action documentation
runs-on: ubuntu-latest
needs: [build-docs-image, set-env]
outputs:
readme: ${{ steps.set-output.outputs.readme }}
container:
image: '${{ needs.set-env.outputs.image_name }}:${{ needs.set-env.outputs.image_tag }}'
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: read
packages: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate action documentation
run: gh-actions-docs
env:
IGNORE_FILES: 'my-new-action/action.yml'
IGNORE_HEADERS: '# core-github-actions-templates,## Table of Contents'
RUN_PRETTIER: 'true'
- name: Set output
id: set-output
run: |
{
echo 'readme<<EOF'
cat README.md | base64
echo EOF
} >> "$GITHUB_OUTPUT"
commit-docs:
name: Commit action documentation on push
runs-on: ubuntu-latest
needs: [generate-docs]
permissions:
contents: write
if: github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get README from output
run: echo '${{ needs.generate-docs.outputs.readme }}' | base64 -d > README.md
- name: Commit changes
shell: bash
run: |
if [[ -z "$(git status --porcelain)" ]]; then
echo 'No changes to commit.'
exit 0
fi
git config user.name github-actions
git config user.email [email protected]
git add README.md
git commit -m 'Update action documentation'
git push