84 lines
1.9 KiB
YAML
84 lines
1.9 KiB
YAML
stages:
|
|
- build
|
|
- test
|
|
- version
|
|
- deploy
|
|
|
|
build:
|
|
stage: build
|
|
image: rust:1.85
|
|
script:
|
|
- cargo build --release
|
|
- ls -R target/release/
|
|
artifacts:
|
|
paths:
|
|
- target/release/
|
|
expire_in: 1 week
|
|
cache:
|
|
key: "cargo-cache"
|
|
paths:
|
|
- target/
|
|
- ~/.cargo/
|
|
|
|
test:
|
|
stage: test
|
|
image: rust:1.85
|
|
script:
|
|
- cargo test
|
|
cache:
|
|
key: "cargo-cache"
|
|
paths:
|
|
- target/
|
|
- ~/.cargo/
|
|
|
|
test_variable:
|
|
stage: test
|
|
image: rust:1.85
|
|
script:
|
|
- echo "Checking CARGO_LOGIN_TOKEN..."
|
|
- if [[ -z "$CARGO_LOGIN_TOKEN" ]]; then echo "CARGO_LOGIN_TOKEN is empty!"; exit 1; else echo "CARGO_LOGIN_TOKEN is set."; fi
|
|
- env
|
|
rules:
|
|
- if: '$CI_COMMIT_TAG'
|
|
|
|
extract_version:
|
|
stage: version
|
|
image: alpine:latest
|
|
script:
|
|
- apk add --no-cache jq
|
|
- VERSION=$(grep 'version = "' Cargo.toml | awk -F'"' '{print $2}' | head -n 1)
|
|
- VER_HASH=${CI_COMMIT_SHA:0:10}
|
|
- VERSION="$VERSION-$VER_HASH"
|
|
- if [ $? -ne 0 ]; then echo "Error extracting version"; exit 1; fi
|
|
- echo "Extracted version is"
|
|
- echo "$VERSION"
|
|
- echo "VERSION=$VERSION" > version.env
|
|
artifacts:
|
|
reports:
|
|
dotenv: version.env
|
|
|
|
tag_release:
|
|
stage: deploy
|
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
|
rules:
|
|
- if: '($CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main") && $CI_PIPELINE_SOURCE == "push"'
|
|
dependencies:
|
|
- extract_version
|
|
script:
|
|
- release-cli create --name "Release $CI_COMMIT_BRANCH-v$VERSION" --tag-name "$CI_COMMIT_BRANCH-v$VERSION"
|
|
|
|
deploy:
|
|
stage: deploy
|
|
image: rust:1.85
|
|
script:
|
|
- echo "Deployment will be configured when this is ready for use"
|
|
# - env
|
|
# Uncomment when you are ready for this to be published
|
|
# - cargo login "$CARGO_LOGIN_TOKEN"
|
|
# - cargo publish
|
|
dependencies:
|
|
- build
|
|
rules:
|
|
- if: '$CI_COMMIT_TAG'
|
|
|