Update .gitlab-ci.yml file

This commit is contained in:
WinterMyst 2024-09-23 15:58:07 +00:00
parent 873b98f578
commit 41f7aa4426

View File

@ -7,7 +7,7 @@ compile:
stage: compile stage: compile
image: ubuntu:latest image: ubuntu:latest
before_script: before_script:
# Install Node.js v21.7.3 manually # Install Node.js v21.x manually
- apt-get update && apt-get install -y curl - apt-get update && apt-get install -y curl
- curl -fsSL https://deb.nodesource.com/setup_21.x | bash - - curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
- apt-get install -y nodejs - apt-get install -y nodejs
@ -20,89 +20,80 @@ compile:
- gulp compile - gulp compile
only: only:
- branches - branches
artifacts:
paths:
- kidsonbrooms.zip
expire_in: never
# Release Job (manually triggered with version) # Release Job (manually triggered with version)
release: release:
stage: release stage: release
image: ubuntu:latest image: ubuntu:latest
before_script: before_script:
# Install Node.js v21.7.3 manually # Install necessary tools
- apt-get update && apt-get install -y curl jq git openssh-client - apt-get update && apt-get install -y curl jq git
# Install Node.js v21.x manually
- curl -fsSL https://deb.nodesource.com/setup_21.x | bash - - curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
- apt-get install -y nodejs - apt-get install -y nodejs
- node -v # Verify the correct Node.js version - node -v # Verify the correct Node.js version
# Install Gulp globally # Install Gulp globally
- npm install --global gulp-cli - npm install --global gulp-cli
- gulp --version # Verify Gulp is installed - gulp --version # Verify Gulp is installed
# Set Git configuration
- git config --global user.name "GitLab CI"
- git config --global user.email "ci@gitlab.com"
# Use the PAT for authentication
- git remote set-url --push origin "https://$CI_COMMITTER_USER_AND_TOKEN@gitlab.com/wintermyst/kidsonbrooms.git"
- git fetch --unshallow # Ensure we fetch all history for the branch (not a shallow clone)
- git checkout master # Switch to the master branch
- git branch --set-upstream-to=origin/master master # Set the upstream to the master branch
script: script:
# Check if VERSION is provided # Check if VERSION is provided
- | - |
if [ -z "$VERSION" ]; then echo "Error: VERSION variable is required." && exit 1; fi if [ -z "$VERSION" ]; then
echo "Error: VERSION variable is required."
exit 1
fi
# Install dependencies and run Gulp release task
- npm install - npm install
# Run Gulp release task (includes zipping)
- gulp release - gulp release
# Create a release on GitLab # Update system.json with the release URL
- >
curl --request POST \
--header "PRIVATE-TOKEN: ${GITLAB_PAT}" \
--header "Content-Type: application/json" \
--data "{
\"name\": \"Release v$VERSION\",
\"tag_name\": \"v$VERSION\",
\"description\": \"Release v$VERSION\",
\"ref\": \"master\",
\"assets\": {
\"links\": [
{
\"name\": \"Download kidsonbrooms.zip\",
\"url\": \"https://gitlab.com/wintermyst/kidsonbrooms/-/jobs/$CI_JOB_ID/artifacts/download\"
}
]
}
}" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/releases"
# Update system.json
- export RELEASE_URL=$(echo $RELEASE_RESPONSE | jq -r '.assets.links[0].url')
# Update the system.json file with the release URL
- | - |
sed -i "s|\"download\":.*|\"download\": \"$RELEASE_URL\",|" system.json sed -i "s|\"download\":.*|\"download\": \"https://gitlab.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/-/releases/v$VERSION/download\",|" system.json
- git config --global user.name "GitLab CI"
- git config --global user.email "ci@gitlab.com"
- git add system.json - git add system.json
- git commit -m "Update system.json with release URL" - git commit -m "Update system.json with release URL"
- git push origin master - git push "https://oauth2:${GITLAB_PAT}@gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}.git" HEAD:master
# Publish the release to the Foundry API # Publish the release to the Foundry API
- | - |
curl -X POST https://api.foundryvtt.com/_api/packages/release_version/ \ curl -X POST https://api.foundryvtt.com/_api/packages/release_version/ \
-H "Authorization: $FOUNDRY_API_KEY" \ -H "Authorization: $FOUNDRY_API_KEY" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d "{
"id": "Your-Package-ID", \"id\": \"Your-Package-ID\",
"release": { \"release\": {
"version": "'$VERSION'", \"version\": \"$VERSION\",
"manifest": "https://gitlab.com/wintermyst/kids-nbrooms/-/raw/master/system.json", \"manifest\": \"https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/raw/master/system.json\",
"notes": "https://gitlab.com/wintermyst/kidsonbrooms/releases/tag/v'$VERSION'", \"notes\": \"https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/releases/v$VERSION\",
"compatibility": { \"compatibility\": {
"minimum": "12.331", \"minimum\": \"12.331\",
"verified": "12.331", \"verified\": \"12.331\",
"maximum": "" \"maximum\": \"\"
} }
} }
}' }"
only: only:
- master - master
when: manual when: manual
allow_failure: false allow_failure: false
dependencies:
- compile
artifacts: artifacts:
paths: paths:
- kidsonbrooms.zip - kidsonbrooms.zip
expire_in: never expire_in: never
release:
name: "Release v$VERSION"
tag_name: "v$VERSION"
description: "Release v$VERSION"
ref: master
assets:
links:
- name: "Download kidsonbrooms.zip"
url: "https://gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/jobs/${CI_JOB_ID}/artifacts/raw/kidsonbrooms.zip"