variables:
# Hack to "expand" file variables: https://gitlab.com/gitlab-org/gitlab/-/issues/29407
GIT_SSH_COMMAND: ssh -i $CI_PROJECT_DIR/../$CI_PROJECT_NAME.tmp/SSH_PRIVATE_KEY -o StrictHostKeyChecking=no
cache:
key: $CI_JOB_NAME
paths:
target/
# In the original format any unrecognized key is a job. However serde_derive doesn't support this for non-self-describing formats and I didn't want to bother writing my own implementation of Deserialize.
jobs:
# TODO: job name changed from rust-ci:test since simple config doesn't support quoted keys yet.
rust-ci-test:
only:
branches
stage: test
image: rust
# In Simple Config it would be more idiomatic to make this a multi-line string rather than a list of commands.
script:
:
[[ "$RUST_CI__DEBIAN_PACKAGES" ]] \
&& apt-get update \
&& apt-get install -y $RUST_CI__DEBIAN_PACKAGES
cargo --version
cargo test --all
rust-ci-tag:
stage: deploy
image: rust
rules:
:
if: $CI_COMMIT_BRANCH =~ /^v\d+(\.\d+)?$/
when: on_success
:
when: never
variables:
GIT_DEPTH: 100
script:
git fetch
desc="$(git describe --first-parent --tags --match "$CI_COMMIT_BRANCH.*" --long || echo "$CI_COMMIT_BRANCH.0.0-00-g0")"
:
[[ "${desc#$CI_COMMIT_BRANCH}" =~ ^\.([0-9]+)((\.[0-9]+)*)-([0-9]+)-g[0-9a-f]+ ]]
current="${BASH_REMATCH[1]}"
suffix="$(sed -E 's/[0-9]+/0/g' <<<"${BASH_REMATCH[3]}")"
distance="${BASH_REMATCH[4]}"
[[ "$distance" != 0 ]] || exit 0
version="$CI_COMMIT_BRANCH.$((current + distance))$suffix"
echo "Releasing version: $version"
git tag "$version"
chmod 600 "$SSH_PRIVATE_KEY"
git push "$(sed -E 's_^.*@([^/]*)/_git@\1:_' <<<"$CI_REPOSITORY_URL")" "$version"
rust-ci-publish:
stage: deploy
image: rust
rules:
:
if: $CI_COMMIT_TAG =~ /^v\d+.\d+.\d+$/
when: on_success
:
when: never
script:
echo "Releasing version: $CI_COMMIT_TAG"
:
sed -i -E "s/^version\s+=.*/version = \"${CI_COMMIT_TAG#v}\"/" Cargo.toml
cargo publish --no-verify --allow-dirty