-
Notifications
You must be signed in to change notification settings - Fork 13
183 lines (172 loc) · 7.02 KB
/
release.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Release
on:
schedule:
- cron: '0 12 ? * MON' # At 12:00 PM every Monday
workflow_dispatch:
inputs:
release_notes:
description: 'Release notes'
required: true
default: 'Updated to the latest version of the source dictionary files'
dry_run:
description: "Dry run: don't create a release, don't commit checksums"
required: true
type: boolean
default: false
force:
description: "Force: proceed even if XML files haven't changed"
required: true
type: boolean
default: false
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- name: Download source files
run: |
./gradlew clean
./gradlew download
- name: Check for updates
if: ${{ !inputs.force }}
shell: bash
run: |
jmdict_updated=$(./gradlew --quiet jmdictHasChanged)
jmdict_examples_updated=$(./gradlew --quiet jmdictExamplesHasChanged)
jmnedict_updated=$(./gradlew --quiet jmnedictHasChanged)
kanjidic_updated=$(./gradlew --quiet kanjidicHasChanged)
echo "JMDICT_UPDATED=$jmdict_updated" >> $GITHUB_ENV
echo "JMDICT_EXAMPLES_UPDATED=$jmdict_examples_updated" >> $GITHUB_ENV
echo "JMNEDICT_UPDATED=$jmnedict_updated" >> $GITHUB_ENV
echo "KANJIDIC_UPDATED=$kanjidic_updated" >> $GITHUB_ENV
if [[ "$jmdict_updated" = "YES" ]] || \
[[ "$jmdict_examples_updated" = "YES" ]] || \
[[ "$jmnedict_updated" = "YES" ]] || \
[[ "$kanjidic_updated" = "YES" ]]
then
echo "SOMETHING_UPDATED=YES" >> $GITHUB_ENV
fi
- name: Set force update variables
if: ${{ inputs.force }}
run: |
echo "JMDICT_UPDATED=YES" >> $GITHUB_ENV
echo "JMDICT_EXAMPLES_UPDATED=YES" >> $GITHUB_ENV
echo "JMNEDICT_UPDATED=YES" >> $GITHUB_ENV
echo "KANJIDIC_UPDATED=YES" >> $GITHUB_ENV
echo "SOMETHING_UPDATED=YES" >> $GITHUB_ENV
- name: Convert dictionaries
if: env.SOMETHING_UPDATED == 'YES'
run: ./gradlew convert
- name: Setup Node.js
if: env.SOMETHING_UPDATED == 'YES'
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Install NPM dependencies
if: env.SOMETHING_UPDATED == 'YES'
working-directory: node
run: npm ci
- name: Build Node packages
if: env.SOMETHING_UPDATED == 'YES'
working-directory: node
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
run: npm run build
- name: Validate dictionary JSON files
if: env.SOMETHING_UPDATED == 'YES'
working-directory: node
run: npm run validate
- name: Create archives
if: env.SOMETHING_UPDATED == 'YES'
run: ./gradlew archive
- name: Set build info
if: env.SOMETHING_UPDATED == 'YES'
run: |
build_time_human=$(date --utc +'%Y-%m-%d %H:%M:%S UTC')
build_time_only_numbers=$(date --utc +%Y%m%d%H%M%S)
build_version_number=$(./gradlew properties | grep 'version: .*' | cut -d' ' -f2 | tr -d '[:space:]')
build_version_metadata=$build_time_only_numbers
build_tag="${build_version_number}+${build_version_metadata}"
echo "BUILD_VERSION_NUMBER=$build_version_number" >> $GITHUB_ENV
echo "BUILD_VERSION_METADATA=$build_version_metadata" >> $GITHUB_ENV
echo "BUILD_TAG=$build_tag" >> $GITHUB_ENV
echo "BUILD_TIME=$build_time_human" >> $GITHUB_ENV
- name: Set release notes for scheduled releases
if: env.SOMETHING_UPDATED == 'YES' && !inputs.release_notes
shell: bash
run: |
RELEASE_NOTES="Updated dictionaries:\n\n"
if [[ "$JMDICT_UPDATED" = "YES" ]]; then
RELEASE_NOTES="${RELEASE_NOTES}- JMdict\n"
fi
if [[ "$JMDICT_EXAMPLES_UPDATED" = "YES" ]]; then
RELEASE_NOTES="${RELEASE_NOTES}- JMdict with examples\n"
fi
if [[ "$JMNEDICT_UPDATED" = "YES" ]]; then
RELEASE_NOTES="${RELEASE_NOTES}- JMnedict\n"
fi
if [[ "$KANJIDIC_UPDATED" = "YES" ]]; then
RELEASE_NOTES="${RELEASE_NOTES}- Kanjidic\n"
fi
WARNING="NOTE: This is a scheduled automated release. It may not have been reviewed by a human."
RELEASE_NOTES="$RELEASE_NOTES\n$WARNING"
echo "RELEASE_NOTES=$RELEASE_NOTES" >> $GITHUB_ENV
- name: Set release notes for manual releases
if: env.SOMETHING_UPDATED == 'YES' && inputs.release_notes
run: |
RELEASE_NOTES='${{ inputs.release_notes }}'
echo "RELEASE_NOTES=$RELEASE_NOTES" >> $GITHUB_ENV
- name: Rename archives # add version build timestamp as version metadata
if: env.SOMETHING_UPDATED == 'YES'
run: |
for f in ./build/distributions/*.zip; do
mv $f ${f/$BUILD_VERSION_NUMBER/$BUILD_TAG}
done
for f in ./build/distributions/*.tgz; do
mv $f ${f/$BUILD_VERSION_NUMBER/$BUILD_TAG}
done
- name: Create release
if: env.SOMETHING_UPDATED == 'YES' && !inputs.dry_run
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# collect assets
assets=()
for asset in ./build/distributions/*.zip; do
assets+=("$asset")
done
for asset in ./build/distributions/*.tgz; do
assets+=("$asset")
done
release_notes=./build/distributions/release-${BUILD_TAG}.md
touch $release_notes
# create release message
echo -e "${BUILD_VERSION_NUMBER}, update ${BUILD_TIME}" > $release_notes
echo -e "\n\n${RELEASE_NOTES}" >> $release_notes
echo -e "\n\n## JMdict\n\n" >> $release_notes
cat ./build/dict-json/jmdict-release-info.md >> $release_notes
echo -e "\n\n## JMdict with examples\n\n" >> $release_notes
cat ./build/dict-json/jmdict-examples-release-info.md >> $release_notes
echo -e "\n\n## JMnedict\n\n" >> $release_notes
cat ./build/dict-json/jmnedict-release-info.md >> $release_notes
echo -e "\n\n## Kanjidic\n\n" >> $release_notes
cat ./build/dict-json/kanjidic-release-info.md >> $release_notes
# create a release
gh release create $BUILD_TAG --notes-file $release_notes "${assets[@]}"
- name: Update checksums
if: env.SOMETHING_UPDATED == 'YES'
run: ./gradlew updateChecksums
- name: Commit XML files checksums
if: env.SOMETHING_UPDATED == 'YES' && !inputs.dry_run
uses: EndBug/add-and-commit@v9
with:
add: "checksums/*.sha256"
message: Update checksum files @ ${{ env.BUILD_TIME }}