-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (147 loc) · 5.52 KB
/
publish.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Publish
on:
workflow_dispatch:
push:
tags:
- '*'
jobs:
publish:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup JDK 16
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '16'
cache: 'gradle'
- name: Build
run: ./gradlew build --no-daemon
- name: Publish to Infernal Studios Maven
run: ./gradlew publish --no-daemon
env:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
artifacts: "./build/libs/*"
token: ${{ secrets.GITHUB_TOKEN }}
name: Release ${{ steps.get_version.outputs.VERSION }}
docs:
runs-on: ubuntu-latest
permissions:
contents: write
if: success()
needs: [ publish ]
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup JDK 16
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '16'
cache: 'gradle'
- name: Setup
id: setup
run: |
echo "::group::Generating temporary directories..."
gitdir=`mktemp -d`
moddir=`mktemp -d`
docsdir=`mktemp -d`
echo "::endgroup::"
echo "::group::Cloning repository"
echo "::debug::Cloning repository to $gitdir"
git clone "https://github.com/$GITHUB_REPOSITORY.git" "$gitdir" --depth=1 --progress --branch=main --single-branch --verbose
echo "::debug::Cloning repository to $docsdir"
git clone "https://github.com/$GITHUB_REPOSITORY.git" "$docsdir" --depth=1 --progress --branch=docs --single-branch --verbose
echo "::endgroup::"
echo "::group::Setting up cloned repositories"
cd "$gitdir"
git config advice.detachedHead false
if ! git checkout --force "$GITHUB_SHA"; then
echo "::error::Failed to checkout $GITHUB_SHA"
exit 1
fi
cd "$docsdir"
if ! git checkout --force "origin/docs"; then
echo "::error::Failed to checkout origin/docs"
exit 1
fi
rm -rfv .git README
echo "::endgroup::"
echo ""
echo "::set-output name=gitdir::$gitdir"
echo "::set-output name=moddir::$moddir"
echo "::set-output name=docsdir::$docsdir"
- name: Generate
env:
DIRECTORY: "./build/docs/javadoc"
run: |
gitdir="${{ steps.setup.outputs.gitdir }}"
moddir="${{ steps.setup.outputs.moddir }}"
docsdir="${{ steps.setup.outputs.docsdir }}"
cd "$gitdir"
echo "::endgroup::"
echo "::group::Generating documentation"
./gradlew javadoc
echo "::endgroup::"
echo "::group::Copying documentation to temporary directory"
mv -vf "$gitdir/$DIRECTORY"/* $moddir
echo "::endgroup::"
- name: Publish
run: |
gitdir="${{ steps.setup.outputs.gitdir }}"
moddir="${{ steps.setup.outputs.moddir }}"
docsdir="${{ steps.setup.outputs.docsdir }}"
gitmessage="$GITHUB_SHA
This is an automated commit by a GitHub workflow.
It contains generated documentation from the main branch of this repository.
Action: https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
moddirhash=`find "$moddir" -type f | xargs sha512sum | cut -d ' ' -f 1`
docsdirhash=`find "$docsdir" -type f | xargs sha512sum | cut -d ' ' -f 1`
if [[ "$moddirhash" != "$docsdirhash" ]]; then
echo "Documentation changed, publishing..."
cd "$moddir"
echo "::group::Preparing commit"
git init
git remote add origin "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git"
echo "This is an automated branch. Please do not commit to or change any files in it." >> README
git add . -v
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git branch -m docs
echo "::endgroup::"
echo "::group::Committing changes"
git commit --verbose -m "$gitmessage"
echo "::endgroup::"
echo "::group::Pushing changes"
git push origin docs --force --verbose
echo "::endgroup::"
else
echo "Documentation hasn't changed, skipping publish."
fi
- name: Cleanup
run: |
gitdir="${{ steps.setup.outputs.gitdir }}"
moddir="${{ steps.setup.outputs.moddir }}"
docsdir="${{ steps.setup.outputs.docsdir }}"
cd ~
echo "::group::Removing $gitdir"
rm -rfv "$gitdir"
echo "::endgroup::"
echo "::group::Removing $moddir"
rm -rfv "$moddir"
echo "::endgroup::"
echo "::group::Removing $docsdir"
rm -rfv "$docsdir"
echo "::endgroup::"