Skip to content

Commit ed0f1cd

Browse files
committed
Initial repository - Github Semantic Versioning.
0 parents  commit ed0f1cd

File tree

6 files changed

+353
-0
lines changed

6 files changed

+353
-0
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
const axios = require('axios');
2+
const fs = require('fs');
3+
4+
async function main()
5+
{
6+
// Grab the environment variables.
7+
const API_URL = "https://godotengine.org/asset-library/api";
8+
const username = process.env.GODOT_LIBRARY_USERNAME;
9+
const password = process.env.GODOT_LIBRARY_PASSWORD;
10+
const assetName = process.env.GODOT_LIBRARY_ASSET_NAME;
11+
const assetId = process.env.GODOT_LIBRARY_ASSET_ID;
12+
const version = process.env.VERSION
13+
14+
// Validate the environment variables.
15+
if (!version)
16+
{
17+
throw new Error("Please set the VERSION environment variable.");
18+
}
19+
if (!username || !password)
20+
{
21+
throw new Error("Please set the GODOT_LIBRARY_USERNAME and GODOT_LIBRARY_PASSWORD environment variables.");
22+
}
23+
if (!assetName && !assetId)
24+
{
25+
throw new Error("Please set the GODOT_LIBRARY_ASSET_NAME or GODOT_LIBRARY_ASSET_ID environment variable.");
26+
}
27+
28+
// Login into the Godot Asset Library.
29+
console.log("Logging in to Godot Asset Library...");
30+
const loginResponse = await axios.post(`${API_URL}/login`, {
31+
username: username,
32+
password: password
33+
});
34+
const token = loginResponse.data.token;
35+
if (!token)
36+
{
37+
throw new Error("Login failed: No token received.");
38+
}
39+
console.log("Login successful! Token received.");
40+
41+
// Fetch the first reference to the asset either by name or ID, in each page.
42+
let page = 1;
43+
let asset = null;
44+
while (asset == null && page <= 100)
45+
{
46+
console.log(`Fetching page ${page}...`);
47+
const { data } = await axios.post(`${API_URL}/user/feed`, {
48+
page: page,
49+
max_results: 100,
50+
token: token,
51+
}, {
52+
headers: {
53+
'Authorization': `Bearer ${token}`
54+
}
55+
});
56+
const assets = data.events || data.results || [];
57+
console.log(`Received Page ${page}, data: ${JSON.stringify(assets, null, 2)}`);
58+
if (!Array.isArray(assets) || assets.length === 0)
59+
{
60+
console.log("No more assets found.");
61+
break;
62+
}
63+
64+
for (const a of assets)
65+
{
66+
if ((assetName && a.title === assetName) || (assetId && a.asset_id === assetId))
67+
{
68+
asset = a;
69+
break;
70+
}
71+
}
72+
73+
page++;
74+
}
75+
76+
// Verify if the asset was found.
77+
if (asset == null)
78+
{
79+
throw new Error(`Asset "${assetName}" not found in the Godot Asset Library.`);
80+
}
81+
82+
// Log the asset details.
83+
console.log(`Asset "${asset.title}" found!`);
84+
console.log(`Asset ID: ${asset.asset_id} | Edit ID: ${asset.edit_id} | Version: ${asset.version_string} -> ${version} | Last Modified: ${asset.modify_date} | Status: ${asset.status}`);
85+
86+
// Check if asset-description.md or asset-description.txt exists.
87+
const descriptionFile = fs.existsSync("asset-description.md") ? "asset-description.md" : "asset-description.txt";
88+
var description = null;
89+
if (fs.existsSync(descriptionFile))
90+
{
91+
console.log(`Reading description from ${descriptionFile}...`);
92+
description = fs.readFileSync(descriptionFile, 'utf8');
93+
}
94+
// Check if there is a asset-package.json file.
95+
const packageFile = "asset-package.json";
96+
var assetPackageData = null;
97+
if (fs.existsSync(packageFile))
98+
{
99+
console.log(`Reading package data from ${packageFile}...`);
100+
assetPackageData = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
101+
}
102+
103+
104+
// If the asset is not approved, we have to edit it differently than when it has been already approved before.
105+
if (asset.status === "new") // Edit the existing asset.
106+
{
107+
const { data: editedAssetData } = await axios.get(`${API_URL}/asset/edit/${asset.edit_id}`, {
108+
token: token,
109+
}, {
110+
headers: {
111+
"Authorization": `Bearer ${token}`
112+
}
113+
});
114+
115+
const sendBlob = {
116+
"token": token,
117+
...editedAssetData,
118+
// Overwrite the data inside the edited asset data.
119+
"version_string": version,
120+
"download_provider": "Custom",
121+
"download_commit": `https://github.com/GDBuildSystem/GDBuildSystem/releases/download/v${version}/gdbuildsystem-${version.replaceAll(".", "_")}.zip`,
122+
"description": description,
123+
...assetPackageData
124+
}
125+
console.log("Patching existing asset edit...\n", sendBlob);
126+
127+
const editResponse = await axios.post(`${API_URL}/asset/edit/${asset.edit_id}`, sendBlob);
128+
if (editResponse.status !== 200)
129+
{
130+
throw new Error(`Failed to edit asset: ${editResponse.reason}`);
131+
}
132+
133+
// Print out the data.
134+
console.log("Patch response:", JSON.stringify(editResponse.data, null, 2));
135+
}
136+
else // Create a new asset version.
137+
{
138+
const sendBlob = {
139+
"token": token,
140+
...asset,
141+
"version_string": version,
142+
"download_url": `https://github.com/GDBuildSystem/GDBuildSystem/releases/download/v${version}/gdbuildsystem-${version}.zip`,
143+
"description": description,
144+
...assetPackageData
145+
}
146+
147+
console.log("Creating new asset edit...\n", sendBlob);
148+
149+
const editResponse = await axios.post(`${API_URL}/asset/${asset.asset_id}`, sendBlob);
150+
if (editResponse.status !== 200)
151+
{
152+
throw new Error(`Failed to edit asset: ${editResponse.reason}`);
153+
}
154+
}
155+
156+
console.log("Asset modified successfully!");
157+
}
158+
159+
// Run the main function and handle errors.
160+
main().then(() =>
161+
{
162+
console.log("Done!");
163+
}
164+
).catch((error) =>
165+
{
166+
console.error("Error:", error);
167+
process.exit(1);
168+
}
169+
).finally(() =>
170+
{
171+
console.log("Finished script execution.");
172+
});

.github/workflows/package.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Package GDBuildSystem
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write # Needed for the release process
12+
13+
jobs:
14+
semantic-versioning:
15+
runs-on: ubuntu-latest
16+
17+
outputs:
18+
version: ${{ steps.semantic-release.outputs.version }}
19+
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: '22'
29+
30+
- name: Install dependencies
31+
run: |
32+
npm init -y
33+
npm install --save-dev semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/github @semantic-release/git
34+
npm install
35+
36+
- id: semantic-release
37+
name: Run semantic-release
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
npx semantic-release | tee semantic-release.log
42+
# Extract the version from the log, which is in the format of "1.1.0-dev.14" or "1.1.0". So we would have to handle any characters after an optional hyphen, and one dot then a number.
43+
VERSION=$(grep -oP 'Published release \K[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z\.-]+)?' semantic-release.log | head -n 1)
44+
# Last ditch effort to get the version.
45+
if [ -z "$VERSION" ]; then
46+
# When the new release version is not found in the log, we can try extracting the found last version from the log.
47+
# Starts with 'Found git tag'
48+
VERSION=$(grep -oP 'Found git tag v\K[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z\.-]+)?' semantic-release.log | head -n 1)
49+
fi
50+
if [ -z "$VERSION" ]; then
51+
echo "No version found in semantic-release output"
52+
exit 1
53+
fi
54+
echo "Version found: $VERSION"
55+
echo "VERSION=$VERSION" >> $GITHUB_ENV
56+
echo "version=$VERSION" >> $GITHUB_OUTPUT
57+
58+
59+
package:
60+
runs-on: ubuntu-latest
61+
needs:
62+
- semantic-versioning
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@v3
67+
68+
- name: Create addons folder and move GDBuildSystem
69+
run: |
70+
export VERSION=$(echo "${{ needs.semantic-versioning.outputs.version }}" | tr '.' '_' )
71+
echo "VERSION=$VERSION" >> $GITHUB_ENV
72+
echo "VERSION: $VERSION"
73+
# Update the version in plugin.cfg
74+
# Format version="myversion"
75+
sed -i "s/version=\".*\"/version=\"$VERSION\"/" gdbuildsystem/plugin.cfg
76+
77+
# Create addons folder and move GDBuildSystem
78+
mkdir addons
79+
mv gdbuildsystem addons/
80+
81+
- name: Zip the addons folder
82+
run: |
83+
zip -r gdbuildsystem-$VERSION.zip addons
84+
85+
- name: Upload the zip file as an artifact
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: addons-zip
89+
path: gdbuildsystem-$VERSION.zip
90+
retention-days: 1
91+
92+
- name: Upload asset with gh CLI
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
run: |
96+
gh release upload v${{ needs.semantic-versioning.outputs.version }} gdbuildsystem-$VERSION.zip --clobber
97+
98+
# Upload to Godot Asset Library;
99+
- name: Upload to Godot Asset Library
100+
env:
101+
GODOT_LIBRARY_USERNAME: ${{ secrets.GODOT_LIBRARY_USERNAME }}
102+
GODOT_LIBRARY_PASSWORD: ${{ secrets.GODOT_LIBRARY_PASSWORD }}
103+
GODOT_LIBRARY_ASSET_NAME: ${{ vars.GODOT_LIBRARY_ASSET_NAME }}
104+
run: |
105+
export VERSION=$(echo "${{ needs.semantic-versioning.outputs.version }}")
106+
npm i axios
107+
node .github/scripts/godot-library-post.js

.releaserc.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is used by semantic-release to automate the release process.
2+
# It includes the configuration for the release process, including the plugins to be used and the conditions for verifying the release.
3+
4+
tagFormat: 'v${version}'
5+
preset: 'angular'
6+
7+
branches:
8+
- name: main
9+
channel: 'latest'
10+
prerelease: false
11+
- name: dev
12+
channel: 'dev'
13+
prerelease: true
14+
15+
verifyConditions:
16+
- '@semantic-release/changelog'
17+
- '@semantic-release/git'
18+
- '@semantic-release/github'
19+
20+
analyzeCommits:
21+
- path: '@semantic-release/commit-analyzer'
22+
23+
generateNotes:
24+
- path: '@semantic-release/release-notes-generator'
25+
writerOpts:
26+
groupBy: 'type'
27+
commitGroupsSort: 'title'
28+
commitsSort: 'header'
29+
linkCompare: true
30+
linkReferences: true
31+
32+
prepare:
33+
- path: '@semantic-release/changelog'
34+
- path: '@semantic-release/git'
35+
message: 'RELEASE: ${nextRelease.version}'
36+
assets: ['CHANGELOG.md']
37+
38+
publish:
39+
- path: '@semantic-release/github'

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 GDBuildSystem
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

asset-description.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This Godot Add-on makes exporting your game easier by providing necessary features into your export pipeline.
2+
3+
Features:
4+
==============================
5+
* Asset Bundling
6+
Simplifies the process of bundling assets without the need for complex scripts or manual work. Simply the user will place files within the designated bundle directory under the bundles directory.
7+
8+
(More soon to come...)

asset-package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "Godot Build System",
3+
"godot_version": "4.4",
4+
"category_id": "5",
5+
"cost": "MIT"
6+
}

0 commit comments

Comments
 (0)