rjw-sexperience-ideology/.gitlab-ci.yml
2026-03-11 19:23:28 +05:00

113 lines
4.3 KiB
YAML

# ### Specify the Docker image
image: mcr.microsoft.com/dotnet/sdk:10.0-alpine
# ### Define variables
variables:
# 1) Name of directory where restore and build objects are stored.
OBJECTS_DIRECTORY: 'IdeologyAddon/obj'
# 2) Name of directory used for keeping restored dependencies.
NUGET_PACKAGES_DIRECTORY: '.nuget'
# 3) A relative path to the source code from project repository root.
SOURCE_CODE_PATH: 'Source/'
# ### Define global cache rule
cache:
# Per-stage and per-branch caching.
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
# 1) Main JSON file holding information about package dependency tree, packages versions,
# frameworks etc. It also holds information where to the dependencies were restored.
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json'
# 2) Other NuGet and MSBuild related files. Also needed.
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.*'
# 3) Path to the directory where restored dependencies are kept.
- '$NUGET_PACKAGES_DIRECTORY'
policy: pull-push
# ### Restore project dependencies
#
# NuGet packages by default are restored to '.nuget/packages' directory
# in the user's home directory. That directory is out of scope of GitLab caching.
#
# To get around this, a custom path can be specified using the '--packages <PATH>' option
# for 'dotnet restore' command. In this example, a temporary directory is created
# in the root of project repository, so its content can be cached.
#
# Learn more about GitLab cache: https://docs.gitlab.com/ee/ci/caching/index.html
#before_script:
# - 'cd $SOURCE_CODE_PATH'
# - 'dotnet restore --packages ../$NUGET_PACKAGES_DIRECTORY'
build:
stage: build
rules:
# Do not build on tags. Release DLLs are commited
- if: $CI_COMMIT_TAG
when: never
# Do not build master branch. It will fail because RealAbout.xml does not exist
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
# Build on commits to a non-default branch with version-suffix
- if: $CI_COMMIT_BRANCH
variables:
VERSION_SUFFIX: "--version-suffix ${CI_COMMIT_BRANCH}"
# Just build in any other case
- when: always
# ### Build all projects discovered from solution file.
script:
- 'cd $SOURCE_CODE_PATH'
- 'dotnet restore --locked-mode --packages ../$NUGET_PACKAGES_DIRECTORY'
- 'dotnet build -c Release --no-restore ${VERSION_SUFFIX}'
- 'cd $CI_PROJECT_DIR/About'
- 'mv -f RealAbout.xml About.xml'
artifacts:
untracked: false
when: on_success
expire_in: 1 day
paths:
- "*" # Include everything
exclude:
- ".*" # Exclude dot files
- ".*/**/*" # Exclude everything in the dot folders
- "Source/**/*" # Exclude everything in the Source folder
update_dev_package:
stage: deploy
needs: [build]
cache: []
rules:
- if: $CI_COMMIT_TAG
when: never # Do not run this job when a tag is created manually
- if: $CI_COMMIT_BRANCH == "dev" # Run this job when commits are pushed or merged to the dev branch
variables:
GIT_STRATEGY: none # Do not clone repo and skip 'before_script'
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_BRANCH}"
script:
- apk add zip
- rm -rf ./1.3 ./1.4
- zip -rq mod.zip ./
- echo "${PACKAGE_REGISTRY_URL}"
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file About/About.xml "${PACKAGE_REGISTRY_URL}/About.xml"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file mod.zip "${PACKAGE_REGISTRY_URL}/rjw_sexperience_ideology.zip"'
create_release:
stage: deploy
image: registry.gitlab.com/gitlab-ci-utils/curl-jq
cache: []
rules:
- if: $CI_COMMIT_TAG =~ /^[0-9].[0-9]+.[0-9].[0-9]+$/
script:
- 'sed -n "/## Version ${CI_COMMIT_TAG}/,/## Version/p" CHANGELOG.md | head -n -2 > descr.txt'
- 'sed -e "s/_TAG_/${CI_COMMIT_TAG}/g" ./Source/ReleaseTemplate.json > temp.json'
- |
jq --rawfile data descr.txt '.description = $data' temp.json > Release.json
- |
curl --header "Content-Type: application/json" \
--header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--data @Release.json \
--request POST \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases"
artifacts:
paths:
- "Release.json"