-
Notifications
You must be signed in to change notification settings - Fork 1
167 lines (150 loc) · 5.93 KB
/
Copy pathbuild.yaml
File metadata and controls
167 lines (150 loc) · 5.93 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
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
name: Build and Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies and build
run: |
npm ci
npm run build
- name: Get last modified file
id: getfile
run: |
last_modified_file=$(ls -Art dist | tail -n 1)
echo "Last modified file: $last_modified_file"
echo "filename=$last_modified_file" >> $GITHUB_OUTPUT
version=$(echo $last_modified_file | sed -n 's/.*-\([0-9.]*\).c3addon/\1/p')
echo "Last modified file version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: Extract changelog for version
id: changelog
run: |
if [ -f "CHANGELOG.json" ]; then
version="${{ steps.getfile.outputs.version }}"
# Extract changelog for this version from JSON
changelog=$(node -e "
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('CHANGELOG.json', 'utf-8'));
if (data['$version']) {
const v = data['$version'];
let output = [];
if (v.added) output.push('**Added:**\\n' + v.added);
if (v.changed) output.push('**Changed:**\\n' + v.changed);
if (v.fixed) output.push('**Fixed:**\\n' + v.fixed);
console.log(output.join('\\n\\n'));
}
")
if [ -n "$changelog" ]; then
echo "Found changelog for version ${{ steps.getfile.outputs.version }}"
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$changelog" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "has_changelog=true" >> $GITHUB_OUTPUT
else
echo "No changelog entry found for this version"
echo "has_changelog=false" >> $GITHUB_OUTPUT
fi
else
echo "No CHANGELOG.json file found"
echo "has_changelog=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/${{ steps.getfile.outputs.filename }}"
body: ${{ steps.changelog.outputs.has_changelog == 'true' && steps.changelog.outputs.changelog || '' }}
omitBody: ${{ steps.changelog.outputs.has_changelog != 'true' }}
tag: ${{ steps.getfile.outputs.filename }}
name: v${{ steps.getfile.outputs.version }}
allowUpdates: true
makeLatest: true
- name: Check if variables are set
id: check
run: |
publish=true
if [[ -z "${{ secrets.C3_AUTH_USER }}" ]]; then
echo "C3 AUTH_USER is not set. skip publishing."
publish=false
fi
if [[ -z "${{ secrets.C3_AUTH_PASSWORD }}" ]]; then
echo "C3 AUTH_PASSWORD is not set. skip publishing."
publish=false
fi
echo "publish=$publish" >> $GITHUB_OUTPUT
- name: Install publish dependencies
if: steps.check.outputs.publish == 'true'
run: |
npm install -g c3addon
- name: Get Addon Url
if: steps.check.outputs.publish == 'true'
id: url
run: |
url=$(grep -oP 'addonUrl:\s?"\K[^"]*' config.caw.js | cut -d '"' -f 1)
echo "Addon Url: $url"
if [[ -z "$url" ]]; then
echo "Addon Url is not set. skip publishing."
exit 1
fi
echo "url=$url" >> $GITHUB_OUTPUT
- name: Publish to Construct 3
if: steps.check.outputs.publish == 'true'
run: |
if [ "${{ steps.changelog.outputs.has_changelog }}" = "true" ]; then
release_notes="${{ steps.changelog.outputs.changelog }}"
else
release_notes="Released via GitHub Actions"
fi
c3addon publish \
--addonUrl '${{steps.url.outputs.url}}' \
--authUser ${{ secrets.C3_AUTH_USER }} \
--authPassword ${{ secrets.C3_AUTH_PASSWORD }} \
--uploadFile dist/${{ steps.getfile.outputs.filename }} \
--version ${{ steps.getfile.outputs.version }} \
--releaseNotes "$release_notes"
- name: Check if itch.io variables are set
id: check_itch
run: |
publish=true
if [[ -z "${{ secrets.BUTLER_API_KEY }}" ]]; then
echo "BUTLER_API_KEY is not set. skip itch.io publishing."
publish=false
fi
echo "publish=$publish" >> $GITHUB_OUTPUT
- name: Get Itch.io Page
if: steps.check_itch.outputs.publish == 'true'
id: itchio
run: |
itchioPage=$(grep -oP 'itchioPage:\s?"\K[^"]*' buildconfig.js | cut -d '"' -f 1)
echo "Itch.io Page: $itchioPage"
if [[ -z "$itchioPage" ]]; then
echo "Itch.io Page is not set. skip itch.io publishing."
exit 1
fi
# Extract username and game ID from "username/game-id" format
itchUsername=$(echo "$itchioPage" | cut -d '/' -f 1)
itchGameId=$(echo "$itchioPage" | cut -d '/' -f 2)
echo "username=$itchUsername" >> $GITHUB_OUTPUT
echo "gameId=$itchGameId" >> $GITHUB_OUTPUT
- name: Publish to Itch.io
if: steps.check_itch.outputs.publish == 'true'
uses: KikimoraGames/itch-publish@v0.0.3
with:
butlerApiKey: ${{ secrets.BUTLER_API_KEY }}
gameData: dist/${{ steps.getfile.outputs.filename }}
itchUsername: ${{ steps.itchio.outputs.username }}
itchGameId: ${{ steps.itchio.outputs.gameId }}
buildChannel: c3addon
buildNumber: ${{ steps.getfile.outputs.version }}