Repository navigation
104 lines (88 loc) · 3.29 KB
/
Copy pathdeploy-apidocs.yml
File metadata and controls
104 lines (88 loc) · 3.29 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
# When changes are pushed to the develop branch,
# build the current version of the API documentation
# with phpDocumentor and deploy it to codeigniter4/api.
name: Deploy API Documentation
on:
push:
branches:
- 'develop'
paths:
- '.github/scripts/secure-git-push'
- '.github/workflows/deploy-apidocs.yml'
- 'system/**'
permissions:
contents: read
jobs:
build:
name: Deploy to api
permissions:
contents: write
if: github.repository == 'codeigniter4/CodeIgniter4'
runs-on: ubuntu-24.04
steps:
- name: Setup credentials
run: |
git config --global user.email "action@github.com"
git config --global user.name "${GITHUB_ACTOR}"
- name: Checkout source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: source
persist-credentials: false
- name: Checkout target
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: codeigniter4/api
token: ${{ secrets.ACCESS_TOKEN }}
path: api
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.2'
coverage: none
- name: Download phpDocumentor
working-directory: source
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
curl_retry() {
curl --fail --silent --show-error --location --retry 5 --retry-all-errors --retry-delay 5 "$@"
}
asset=$(curl_retry \
--header "Authorization: Bearer ${GITHUB_TOKEN}" \
https://api.github.com/repos/phpDocumentor/phpDocumentor/releases/latest \
| jq --compact-output '.assets[] | select(.name == "phpDocumentor.phar")')
url=$(jq --raw-output '.browser_download_url' <<< "${asset}")
sha256=$(jq --raw-output '.digest | sub("^sha256:"; "")' <<< "${asset}")
if [ -z "${url}" ] || ! [[ "${sha256}" =~ ^[0-9a-f]{64}$ ]]; then
echo "Could not resolve the phpDocumentor phar and its SHA-256 digest."
exit 1
fi
mkdir --parents tools
curl_retry --output tools/phpDocumentor "${url}"
echo "${sha256} tools/phpDocumentor" | sha256sum --check --strict
- name: Prepare API repo
working-directory: api
run: |
git reset --hard master
rm -rfv docs
mkdir --parents --verbose docs
- name: Build API in source repo
working-directory: source
run: |
php tools/phpDocumentor --ansi --verbose
cp -R ${GITHUB_WORKSPACE}/source/api/build/* ${GITHUB_WORKSPACE}/api/docs
- name: Deploy to API repo
working-directory: api
env:
PUSH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
git add .
if ! git diff-index --quiet HEAD; then
git commit -m "Updated API for commit ${GITHUB_SHA}"
bash "${GITHUB_WORKSPACE}/source/.github/scripts/secure-git-push" https://github.com/codeigniter4/api.git HEAD:master
echo "API documentation deployed successfully."
else
echo "No changes to deploy."
fi