|
| 1 | +--- |
| 2 | +version: 2.1 |
| 3 | + |
| 4 | +executors: |
| 5 | + python: |
| 6 | + docker: |
| 7 | + - image: cimg/python:3.9 |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + executor: python |
| 12 | + steps: |
| 13 | + - checkout |
| 14 | + - run: pip install ansible-lint yamllint flake8 |
| 15 | + - run: ansible-lint |
| 16 | + - run: yamllint . |
| 17 | + - run: flake8 |
| 18 | + |
| 19 | + test: |
| 20 | + executor: python |
| 21 | + parameters: |
| 22 | + ansible: |
| 23 | + type: string |
| 24 | + environment: |
| 25 | + ANSIBLE: "<< parameters.ansible >>" |
| 26 | + steps: |
| 27 | + - checkout |
| 28 | + - setup_remote_docker |
| 29 | + - run: ln -s ~/project ~/${CIRCLE_PROJECT_REPONAME} |
| 30 | + - run: pip install -r test-requirements.txt |
| 31 | + - run: molecule test -s default --destroy always |
| 32 | + - run: | |
| 33 | + if [[ -d 'molecule/alternative' ]]; then |
| 34 | + molecule test -s alternative --destroy never |
| 35 | + else |
| 36 | + echo 'No alternative test' |
| 37 | + fi |
| 38 | + - run: | |
| 39 | + if [[ -z "${CIRCLE_PULL_REQUEST}" ]]; then |
| 40 | + molecule test -s latest --destroy never |
| 41 | + else |
| 42 | + echo 'Not running latest on PR' |
| 43 | + fi |
| 44 | + release: |
| 45 | + executor: python |
| 46 | + environment: |
| 47 | + |
| 48 | + GIT_USER: cloudalchemybot |
| 49 | + GIT_COMMIT_DESC: git log --format=%B -n 1 ${CIRCLE_SHA1} |
| 50 | + steps: |
| 51 | + - checkout |
| 52 | + - setup_remote_docker |
| 53 | + - run: pip install git-semver |
| 54 | + - run: git config --global user.email "${GIT_MAIL}" |
| 55 | + - run: git config --global user.name "${GIT_USER}" |
| 56 | + - run: | |
| 57 | + GIT_TAG=none |
| 58 | + echo "Last commit message: ${GIT_COMMIT_DESC}" |
| 59 | + case "${GIT_COMMIT_DESC}" in |
| 60 | + *"[patch]"*|*"[fix]"*|*"[bugfix]"* ) GIT_TAG=$(git semver --next-patch) ;; |
| 61 | + *"[minor]"*|*"[feat]"*|*"[feature]"* ) GIT_TAG=$(git semver --next-minor) ;; |
| 62 | + *"[major]"*|*"[breaking change]"* ) GIT_TAG=$(git semver --next-major) ;; |
| 63 | + *) echo "Keyword not detected. Doing nothing" && circleci-agent step halt ;; |
| 64 | + esac |
| 65 | + echo "GIT_TAG=${GIT_TAG}" >> $BASH_ENV |
| 66 | + - run: | |
| 67 | + docker run -it --rm \ |
| 68 | + -v "${CIRCLE_WORKING_DIRECTORY}:/role" \ |
| 69 | + -w "/role" \ |
| 70 | + ferrarimarco/github-changelog-generator:1.15.2 \ |
| 71 | + --user "${CIRCLE_PROJECT_USERNAME}" \ |
| 72 | + --project "${CIRCLE_PROJECT_REPONAME}" \ |
| 73 | + --token "${GH_TOKEN}" \ |
| 74 | + --release-url "https://galaxy.ansible.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME#ansible-}" \ |
| 75 | + --unreleased-label "**Next release**" --no-compare-link \ |
| 76 | + --future-release "${GIT_TAG}" |
| 77 | + - run: git add CHANGELOG.md |
| 78 | + - run: git commit -m "[ci skip] Automatic changelog update" |
| 79 | + - run: git push "https://${GH_TOKEN}:@${GIT_URL}" || circleci-agent step halt |
| 80 | + - run: | |
| 81 | + ghr \ |
| 82 | + -t ${GH_TOKEN} \ |
| 83 | + -u ${CIRCLE_PROJECT_USERNAME} \ |
| 84 | + -r ${CIRCLE_PROJECT_REPONAME} \ |
| 85 | + -n ${GIT_TAG} \ |
| 86 | + -b "$(sed -n -e '/## \[0.22.0\]/,/## \[/ p' CHANGELOG.md | sed -e '$ d')" \ |
| 87 | + ${GIT_TAG} |
| 88 | + galaxy: |
| 89 | + executor: python |
| 90 | + steps: |
| 91 | + - checkout |
| 92 | + - run: pip install ansible |
| 93 | + - run: ansible-galaxy role import --token "${GALAXY_TOKEN}" "${CIRCLE_PROJECT_USERNAME}" "${CIRCLE_PROJECT_REPONAME}" |
| 94 | + |
| 95 | +workflows: |
| 96 | + version: 2 |
| 97 | + molecule: |
| 98 | + jobs: |
| 99 | + - lint: |
| 100 | + filters: |
| 101 | + tags: |
| 102 | + only: /.*/ |
| 103 | + - test: |
| 104 | + matrix: |
| 105 | + parameters: |
| 106 | + ansible: |
| 107 | + - "2.9" |
| 108 | + - "2.10" |
| 109 | + filters: |
| 110 | + tags: |
| 111 | + only: /.*/ |
| 112 | + - release: |
| 113 | + context: release |
| 114 | + requires: |
| 115 | + - lint |
| 116 | + - test |
| 117 | + filters: |
| 118 | + branches: |
| 119 | + only: master |
| 120 | + tags: |
| 121 | + ignore: /.*/ |
| 122 | + - galaxy: |
| 123 | + context: galaxy |
| 124 | + requires: |
| 125 | + - lint |
| 126 | + - test |
| 127 | + - release |
| 128 | + filters: |
| 129 | + branches: |
| 130 | + only: master |
0 commit comments