xmpp-rs/.gitlab-ci.yml
Maxime “pep” Buquet ea0bba58fe
Some checks are pending
Build / lint (push) Waiting to run
Build / test-stable (push) Blocked by required conditions
Build / test-nightly (push) Blocked by required conditions
CI: Force changelog updates
Changelog updates are now required in MRs by default. If there is a
match for "\<skip.\?changelog\>" in the commit message, this will be
ignored.

$CI_COMMIT_MESSAGE mangles newlines so it's not possible to require the
string to be on its own line, that means it would also trigger within a
wall of text, which makes it less obvious.

Also, I wasn't able to find a CI variable which has the ref of the
branch the MR is set against, to build a tree-ish than spans over the
whole MR and not just HEAD.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-12-23 12:06:04 +01:00

137 lines
4.2 KiB
YAML

---
stages:
- lint
- test
- bot
variables:
DOCS_BASEURL: "https://docs.xmpp.rs"
FEATURES: ""
RUST_BACKTRACE: "full"
RUSTFLAGS: " -D warnings"
RUSTDOCFLAGS: " -D warnings"
.show-version:
before_script:
- apt-get update; apt-get install -y --no-install-recommends pkg-config libssl-dev
- rustc --version
- cargo --version
.stable:
image: rust:slim
extends:
- .show-version
.nightly:
image: rustlang/rust:nightly-slim
extends:
- .show-version
.test:
stage: test
script:
- cargo test --verbose
- cargo test --verbose --no-default-features
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_REF_NAME == 'main'
.docs:
stage: test
script:
- echo "Building docs to CI_DOC_TARGET=$CI_DOC_TARGET"
- RUSTDOCFLAGS="--cfg docsrs -D warnings" RUSTFLAGS="--cfg xmpprs_doc_build" cargo +nightly doc --no-deps -Zrustdoc-map --all-features
- apt install -y rsync openssh-client
- mkdir -p $HOME/.ssh
- echo -e "Host docs\n\tHostname docs.xmpp.rs\n\tPort 1312\n\tUser xmpp-rs\n\tStrictHostKeyChecking no" > $HOME/.ssh/config
- echo "$SECRET_DOCS_SSH_PRIVATE" > $HOME/.ssh/id_ed25519
- chmod 400 $HOME/.ssh/id_ed25519
- rsync -av target/doc/ docs:$CI_DOC_TARGET
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
variables:
CI_DOC_TARGET: "$CI_MERGE_REQUEST_IID"
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_REF_NAME == 'main'
variables:
CI_DOC_TARGET: "main"
rustfmt:
stage: lint
script:
- rustup component add rustfmt
- cargo fmt --version
- cargo fmt --check
extends:
- .stable
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_REF_NAME == 'main'
changelog-update:
stage: lint
image: alpine:latest
# Check in the commit message for "skip.?changelog", if not present
# then check for changes in changelogs.
# XXX: It looks like $CI_COMMIT_MESSAGE mangles newlines so it's not
# possible to require the "skip.?changelog" string to be on its own line,
# that means it would also trigger within a wall of text. Not so obvious.
# TODO: Check the whole MR for updates in changelogs, not just the last
# commit.
script:
- apk add --no-cache git python3
- echo $CI_COMMIT_MESSAGE
- |
/usr/bin/env python3 -c "
import os, re, subprocess, sys
# Skip this check if instructed
if re.search(r'skip.?changelog', os.environ['CI_COMMIT_MESSAGE'], flags=re.I) is not None:
print('Changelog skipped.')
sys.exit(0)
subprocess.run(['ls', '-l'])
subprocess.run(['git', '--version'])
treeish = 'main..'
if os.environ['CI_PIPELINE_SOURCE'] == 'merge_request_event':
treeish = '{}..'.format(os.environ['CI_MERGE_REQUEST_DIFF_BASE_SHA'])
subprocess.run(['git', 'log', '--oneline', treeish])
diff=subprocess.run(
['git', 'diff-tree', '--no-commit-id', '-r', treeish],
capture_output=True,
)
print(f'FOO: {diff.stdout}\n\n{diff.stderr}')
# Verify if at least a single changelog file has been added or edited
if re.search(b'[AM]\\s+\\S*changelog', diff.stdout, flags=re.I) is None:
print('Please update the Changelog. Use \"skip-changelog\" in the commit message to skip this check.')
sys.exit(1)
print('Changelog has been updated as expected.')"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_REF_NAME == 'main'
stable-test:
extends:
- .test
- .stable
nightly-test:
# It's not often, but it happens nightly breaks, surprisingly.
allow_failure: true
extends:
- .test
- .nightly
docs:
extends:
- .docs
- .nightly
bot-comment:
stage: bot
image: alpine:latest
script:
- apk add --no-cache glab
- glab mr --repo "$CI_MERGE_REQUEST_PROJECT_PATH" comment $CI_MERGE_REQUEST_IID --unique --message "Thanks for your MR! You can preview the docs [here]($DOCS_BASEURL/$CI_MERGE_REQUEST_IID/)."
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
variables:
GITLAB_TOKEN: $MR_AUTOMATION_TOKEN