-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
70 lines (66 loc) · 2.36 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Define variables
variables:
TEST_RESULTS_FILE: test-results.xml
# Define is_tag rule
.is_tag: &is_tag
if: '$CI_COMMIT_TAG'
when: always
# Define stages
stages:
- test
- publish
# Run BATS tests (always)
bats_tests:
stage: test
image:
name: bats/bats:latest
entrypoint: [ "" ]
script:
- bats --formatter junit "$PWD/tests" > $TEST_RESULTS_FILE
artifacts:
when: always
paths:
- $PWD/$TEST_RESULTS_FILE
reports:
junit: $PWD/$TEST_RESULTS_FILE
# Publish tag (only if tag is being created)
publish_tag:
stage: publish
rules:
- <<: *is_tag
image:
name: alpine/git:latest
entrypoint: [ "" ]
script:
# Set git user
- git config user.name "$CI_USER"
- git config user.email "$CI_USER_EMAIL"
# Set remote
- git remote set-url origin "https://${CI_USER}:${CI_USER_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
# Create temporary branch; this is necessary to replace SCRIPT_VERSION with the tag and commit it
- git show-ref --verify --quiet refs/heads/temp-branch && git branch -D temp-branch || true
- git checkout -b temp-branch
# Replace SCRIPT_VERSION with $CI_COMMIT_TAG
- |
for script in scripts/*.sh; do
sed -i -E "s/(export SCRIPT_VERSION=\")([^\"]+)(\".*)/\1${CI_COMMIT_TAG}\3/" "$script"
done
# Add and commit the changes, update $CI_COMMIT_TAG tag
- git add scripts/*.sh
- git commit -m "Application version '$CI_COMMIT_TAG' [ci skip]"
- git tag -d $CI_COMMIT_TAG || true # Delete $CI_COMMIT_TAG tag locally
- git push origin :refs/tags/$CI_COMMIT_TAG # Delete $CI_COMMIT_TAG tag in origin, too
- git tag -a $CI_COMMIT_TAG -m "Tagging version $CI_COMMIT_TAG [ci skip]" # Create updated $CI_COMMIT_TAG tag locally
- git push origin $CI_COMMIT_TAG # Push updated $CI_COMMIT_TAG to remote
# Fetch all branches, change to master and delete the temporary branch
- git fetch
- |
if git rev-parse --verify $CI_DEFAULT_BRANCH >/dev/null 2>&1; then
# If the branch exists locally
git checkout $CI_DEFAULT_BRANCH
git reset --hard origin/$CI_DEFAULT_BRANCH # Reset the local branch to match origin/branch
else
# If the branch does not exist locally
git checkout -b $CI_DEFAULT_BRANCH origin/$CI_DEFAULT_BRANCH # Create branch based on origin/branch
fi
- git branch -D temp-branch