-
Magnus Svensson authored
New pdk image See merge request puppet-infra/shared-ci-piplines!83
Magnus Svensson authoredNew pdk image See merge request puppet-infra/shared-ci-piplines!83
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
puppet-module-pipeline.yaml 7.37 KiB
---
stages:
- puppet
- pre_deploy
- deploy
workflow:
rules:
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"'
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
variables:
GIT_LFS_SKIP_SMUDGE: 1 # Disable LFS by default
pdk-validate:
stage: puppet
image: &PDK
name: puppet/pdk:3.4.0.1
pull_policy: if-not-present
before_script: &pdk-workaround
- |
# Applying any necessary PDK workarounds
PDK_VERSION="$(pdk --version)"
pdk env 2>/dev/null > /tmp/pdk-env
source /tmp/pdk-env
touch Gemfile Gemfile.local
# For PDK 3.3.0
if [ "$PDK_VERSION" == "3.3.0" ]; then
if [ "$PDK_RESOLVED_RUBY_VERSION" == "2.7.8" ]; then
echo "Locking io-console to 0.5.6"
sed -e '/"io-console"/d' -e "/'io-console'/d" -i Gemfile Gemfile.local
echo 'gem "io-console", "= 0.5.6"' >> Gemfile.local
echo "Locking bigdecimal to 2.0.0"
sed -e '/"bigdecimal"/d' -e "/'bigdecimal'/d" -i Gemfile Gemfile.local
echo 'gem "bigdecimal", "= 2.0.0"' >> Gemfile.local
else
echo "Locking io-console to 0.6.0"
sed -e '/"io-console"/d' -e "/'io-console'/d" -i Gemfile Gemfile.local
echo 'gem "io-console", "= 0.6.0"' >> Gemfile.local
fi
# For PDK 3.2.0 (it can report as the unreleased 3.1.0)
elif [ "$PDK_VERSION" == "3.1.0" ] || [ "$PDK_VERSION" == "3.2.0" ]; then
if [ "$PDK_RESOLVED_RUBY_VERSION" == "2.7.8" ]; then
echo "Locking racc to 1.4.16"
sed -e '/"racc"/d' -e "/'racc'/d" -i Gemfile Gemfile.local
echo 'gem "racc", "= 1.4.16"' >> Gemfile.local
echo "Locking io-console to 0.5.6"
sed -e '/"io-console"/d' -e "/'io-console'/d" -i Gemfile Gemfile.local
echo 'gem "io-console", "= 0.5.6"' >> Gemfile.local
else
echo "Locking racc to 1.7.3"
sed -e '/"racc"/d' -e "/'racc'/d" -i Gemfile Gemfile.local
echo 'gem "racc", "= 1.7.3"' >> Gemfile.local
echo "Locking io-console to 0.6.0"
sed -e '/"io-console"/d' -e "/'io-console'/d" -i Gemfile Gemfile.local
echo 'gem "io-console", "= 0.6.0"' >> Gemfile.local
fi
echo "Locking rexml to 3.2.6"
sed -e '/"rexml"/d' -e "/'rexml'/d" -i Gemfile Gemfile.local
echo 'gem "rexml", "= 3.2.6"' >> Gemfile.local
# For PDK 3.0.1
elif [ "$PDK_VERSION" == "3.0.1" ]; then
echo "Locking puppet_litmus to 1.2.1"
sed -e '/"puppet_litmus"/d' -e "/'puppet_litmus'/d" -i Gemfile Gemfile.local
echo 'gem "puppet_litmus", "= 1.2.1"' >> Gemfile.local
echo "Locking bolt to 3.27.4"
sed -e '/"bolt"/d' -e "/'bolt'/d" -i Gemfile Gemfile.local
echo 'gem "bolt", "= 3.27.4"' >> Gemfile.local
echo "Locking CFPropertyList to 3.0.6"
sed -e '/"CFPropertyList"/d' -e "/'CFPropertyList'/d" -i Gemfile Gemfile.local
echo 'gem "CFPropertyList", "= 3.0.6"' >> Gemfile.local
echo "Locking nori to 2.6.0"
sed -e '/"nori"/d' -e "/'nori'/d" -i Gemfile Gemfile.local
echo 'gem "nori", "= 2.6.0"' >> Gemfile.local
# For PDK 3.0.0
elif [ "$PDK_VERSION" == "3.0.0" ]; then
echo "Locking ffi to 1.15.5"
sed -e '/"ffi"/d' -e "/'ffi'/d" -i Gemfile Gemfile.local
echo 'gem "ffi", "= 1.15.5"' >> Gemfile.local
if [ "$PDK_RESOLVED_RUBY_VERSION" == "2.7.8" ]; then
echo "Locking racc to 1.4.16"
sed -e '/"racc"/d' -e "/'racc'/d" -i Gemfile Gemfile.local
echo 'gem "racc", "= 1.4.16"' >> Gemfile.local
else
echo "Locking racc to 1.6.2"
sed -e '/"racc"/d' -e "/'racc'/d" -i Gemfile Gemfile.local
echo 'gem "racc", "= 1.6.2"' >> Gemfile.local
fi
fi
script:
- pdk validate --parallel --format=junit:validate.xml --format=text
retry:
max: 2
when: runner_system_failure
artifacts:
when: always
paths:
- validate.xml
reports:
junit: validate.xml
pdk-test-unit:
stage: puppet
image: *PDK
before_script: *pdk-workaround
script:
- sed -i "s|git@gitlab.it.liu.se:|https://gitlab+deploy-token-30:$gitlab_deploy_token_30@gitlab.it.liu.se/|g" .fixtures.yml
- pdk test unit --parallel --format=junit:test.xml --format=text
rules:
- if: $CI_PROJECT_NAMESPACE != "pm-liuit" && $CI_PROJECT_NAMESPACE != "pm-liumirror"
when: never
- if: $CI_COMMIT_REF_PROTECTED && $TEST_ENFORCE == "TRUE"
when: always
allow_failure: false
- if: $CI_COMMIT_REF_PROTECTED && $TEST_RUN == "TRUE"
when: always
allow_failure: true
- if: $CI_COMMIT_REF_PROTECTED
when: manual
allow_failure: true
retry:
max: 2
when: runner_system_failure
artifacts:
when: always
paths:
- test.xml
reports:
junit: test.xml
.tagging:
stage: pre_deploy
image:
name: alpine/git
pull_policy: if-not-present
script:
- git config --global user.email "jenkins@gilab.it.liu.se"
- git config --global user.name "GitLabCI"
- git tag -a r10k-$CI_COMMIT_BRANCH -m "Latest good build"
- git push --tags
rules:
- if: $CI_PROJECT_NAMESPACE != "pm-liuit" && $CI_PROJECT_NAMESPACE != "pm-liumirror"
when: never
- if: $CI_MERGE_REQUEST_ID
when: never
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH
puppet-strings:
stage: deploy
image: *PDK
before_script: *pdk-workaround
script:
- pdk bundle
- pdk bundle exec rake strings:generate:reference
- pdk bundle exec puppet strings generate
rules:
- if: $CI_MERGE_REQUEST_ID
when: never
- if: $CI_PROJECT_NAMESPACE != "pm-liuit" && $CI_PROJECT_NAMESPACE != "pm-liumirror"
when: never
- if: $CI_COMMIT_REF_PROTECTED == "false"
when: never
- if: $PUPPET_DEPLOY_TOKEN == null
when: never
- if: $CI_COMMIT_BRANCH == "production"
when: always
allow_failure: true
retry:
max: 2
when: runner_system_failure
artifacts:
paths:
- REFERENCE.md
- doc/
Puppet module deploy:
stage: deploy
image:
name: curlimages/curl
pull_policy: if-not-present
before_script:
- |
# Get module information
test -f metadata.json && export PUPPET_FULLNAME=$(grep '"name"' metadata.json | head -n1 | cut -d: -f2 | awk -F\" '{print $2}') || export PUPPET_FULLNAME=$CI_PROJECT_NAME
export PUPPET_AUTHOR=$(echo $PUPPET_FULLNAME | sed -e 's|/|-|' | cut -d- -f1)
export PUPPET_MODULE=$(echo $PUPPET_FULLNAME | sed -e 's|/|-|' | cut -d- -f2)
script:
- curl -X POST
-F "token=$PUPPET_DEPLOY_TOKEN"
-F "ref=master"
-F "variables[PUPPETMODULE]=$PUPPET_MODULE"
https://gitlab.it.liu.se/api/v4/projects/1185/trigger/pipeline
2>/dev/null | sed -e 's|\(pipelines/\d\+\)".*|\1|' -e 's/.*web_url":"//'
allow_failure: true
rules:
- if: $PUPPET_DEPLOY_TOKEN == null
when: never
- if: $CI_PROJECT_NAMESPACE != "pm-liuit" && $CI_PROJECT_NAMESPACE != "pm-liumirror"
when: never
- if: $CI_COMMIT_REF_PROTECTED == "false"
when: never
- if: $CI_COMMIT_BRANCH == "production"
when: on_success
- if: $CI_COMMIT_BRANCH == "test"
when: on_success
- if: $CI_COMMIT_BRANCH == "devel"
when: on_success
retry:
max: 2
when: runner_system_failure