2024-09-22 01:45:32 +02:00
|
|
|
stages:
|
|
|
|
- compile
|
|
|
|
- release
|
|
|
|
|
|
|
|
# Compile Job (runs on every commit)
|
|
|
|
compile:
|
|
|
|
stage: compile
|
2024-09-22 01:54:53 +02:00
|
|
|
image: ubuntu:latest
|
|
|
|
before_script:
|
|
|
|
# Install Node.js v21.7.3 manually
|
2024-09-22 01:55:02 +02:00
|
|
|
- apt-get update && apt-get install -y curl
|
2024-09-22 01:54:53 +02:00
|
|
|
- curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
|
|
|
|
- apt-get install -y nodejs
|
|
|
|
- node -v # Verify the correct Node.js version
|
|
|
|
# Install Gulp globally
|
2024-09-22 01:45:32 +02:00
|
|
|
- npm install --global gulp-cli
|
2024-09-22 01:54:53 +02:00
|
|
|
- gulp --version # Verify Gulp is installed
|
|
|
|
script:
|
2024-09-22 01:45:32 +02:00
|
|
|
- npm install
|
|
|
|
- gulp compile
|
|
|
|
only:
|
|
|
|
- branches
|
|
|
|
|
|
|
|
# Release Job (manually triggered with version)
|
|
|
|
release:
|
|
|
|
stage: release
|
2024-09-22 01:54:53 +02:00
|
|
|
image: ubuntu:latest # Or any other basic image
|
2024-09-22 01:45:32 +02:00
|
|
|
before_script:
|
2024-09-22 01:54:53 +02:00
|
|
|
# Install Node.js v21.7.3 manually
|
2024-09-22 18:55:51 +02:00
|
|
|
- apt-get update && apt-get install -y curl jq git openssh-client
|
2024-09-22 01:54:53 +02:00
|
|
|
- curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
|
|
|
|
- apt-get install -y nodejs
|
|
|
|
- node -v # Verify the correct Node.js version
|
|
|
|
# Install Gulp globally
|
2024-09-22 01:45:32 +02:00
|
|
|
- npm install --global gulp-cli
|
2024-09-22 01:54:53 +02:00
|
|
|
- gulp --version # Verify Gulp is installed
|
2024-09-22 18:55:51 +02:00
|
|
|
# Prepare SSH
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- chmod 700 ~/.ssh
|
|
|
|
# Decode and set up the SSH private key
|
2024-09-22 19:16:04 +02:00
|
|
|
- |
|
2024-09-22 19:25:21 +02:00
|
|
|
printf '%s' "SSH_PRIVATE_KEY_ENCODED | tr -d '\r\n' | base64 --decode > ~/.ssh/id_rsa
|
2024-09-22 19:16:04 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error: Failed to decode SSH_PRIVATE_KEY_BASE64."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# Verify the key file
|
|
|
|
if [ ! -s ~/.ssh/id_rsa ]; then
|
|
|
|
echo "Error: SSH private key file is empty or does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ssh-keygen -y -f ~/.ssh/id_rsa > /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error: Invalid SSH private key."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# Set permissions
|
2024-09-22 18:55:51 +02:00
|
|
|
- chmod 600 ~/.ssh/id_rsa
|
|
|
|
# Start the SSH agent and add the key
|
|
|
|
- eval $(ssh-agent -s)
|
|
|
|
- ssh-add ~/.ssh/id_rsa
|
|
|
|
# Add GitLab to known hosts to prevent authenticity prompt
|
|
|
|
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
|
|
|
|
# Set Git configuration
|
2024-09-22 17:13:26 +02:00
|
|
|
- git config --global user.name "GitLab CI"
|
|
|
|
- git config --global user.email "ci@gitlab.com"
|
2024-09-22 18:55:51 +02:00
|
|
|
# Update the Git remote to use SSH
|
|
|
|
- git remote set-url origin git@gitlab.com:wintermyst/kidsonbrooms.git
|
|
|
|
# Fetch and check out the master branch
|
|
|
|
- git fetch --unshallow
|
|
|
|
- git checkout master
|
2024-09-22 01:45:32 +02:00
|
|
|
script:
|
|
|
|
# Check if VERSION is provided
|
2024-09-22 01:48:59 +02:00
|
|
|
- |
|
|
|
|
if [ -z "$VERSION" ]; then echo "Error: VERSION variable is required." && exit 1; fi
|
2024-09-22 01:45:32 +02:00
|
|
|
|
2024-09-22 16:56:10 +02:00
|
|
|
- npm install
|
2024-09-22 01:45:32 +02:00
|
|
|
# Run Gulp release task (includes zipping)
|
|
|
|
- gulp release
|
|
|
|
|
|
|
|
# Create a release on GitLab
|
2024-09-22 01:48:59 +02:00
|
|
|
- |
|
|
|
|
export RELEASE_RESPONSE=$(curl --request POST \
|
2024-09-22 18:51:01 +02:00
|
|
|
--header "PRIVATE-TOKEN: ${GITLAB_PAT}" \
|
2024-09-22 01:45:32 +02:00
|
|
|
--header "Content-Type: application/json" \
|
|
|
|
--data '{
|
|
|
|
"name": "Release v'$VERSION'",
|
|
|
|
"tag_name": "v'$VERSION'",
|
|
|
|
"description": "Release v'$VERSION'",
|
|
|
|
"ref": "master",
|
|
|
|
"assets": {
|
|
|
|
"links": [
|
|
|
|
{
|
2024-09-22 15:57:37 +02:00
|
|
|
"name": "Download kidsonbrooms.zip",
|
2024-09-22 16:52:45 +02:00
|
|
|
"url": "https://gitlab.com/wintermyst/kidsonbrooms/-/jobs/$CI_JOB_ID/artifacts/download"
|
2024-09-22 01:45:32 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}' "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/releases")
|
|
|
|
|
|
|
|
# Get the release URL from the response
|
|
|
|
- export RELEASE_URL=$(echo $RELEASE_RESPONSE | jq -r '.assets.links[0].url')
|
|
|
|
|
|
|
|
# Update the system.json file with the release URL
|
2024-09-22 01:48:59 +02:00
|
|
|
- |
|
|
|
|
sed -i "s|\"download\":.*|\"download\": \"$RELEASE_URL\",|" system.json
|
2024-09-22 01:45:32 +02:00
|
|
|
- git add system.json
|
|
|
|
- git commit -m "Update system.json with release URL"
|
|
|
|
- git push origin master
|
|
|
|
|
|
|
|
# Publish the release to the Foundry API
|
2024-09-22 01:48:59 +02:00
|
|
|
- |
|
|
|
|
curl -X POST https://api.foundryvtt.com/_api/packages/release_version/ \
|
2024-09-22 01:45:32 +02:00
|
|
|
-H "Authorization: $FOUNDRY_API_KEY" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d '{
|
|
|
|
"id": "Your-Package-ID",
|
|
|
|
"release": {
|
|
|
|
"version": "'$VERSION'",
|
2024-09-22 15:57:37 +02:00
|
|
|
"manifest": "https://gitlab.com/wintermyst/kids-nbrooms/-/raw/master/system.json",
|
|
|
|
"notes": "https://gitlab.com/wintermyst/kidsonbrooms/releases/tag/v'$VERSION'",
|
2024-09-22 01:45:32 +02:00
|
|
|
"compatibility": {
|
|
|
|
"minimum": "12.331",
|
|
|
|
"verified": "12.331",
|
|
|
|
"maximum": ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}'
|
2024-09-22 16:11:43 +02:00
|
|
|
only:
|
|
|
|
- master
|
2024-09-22 01:45:32 +02:00
|
|
|
when: manual
|
|
|
|
allow_failure: false
|
|
|
|
artifacts:
|
|
|
|
paths:
|
2024-09-22 15:57:37 +02:00
|
|
|
- kidsonbrooms.zip
|
2024-09-22 01:45:32 +02:00
|
|
|
expire_in: never
|