feat(ansible_collection): complete ci jobs for full workflow
!75 nofusscomputing/projects/ansible/collections/ci-test!1
This commit is contained in:
@ -11,6 +11,9 @@ variables:
|
||||
stage: chores
|
||||
image: python:3.11-bookworm
|
||||
before_script:
|
||||
- | # Create artifact directory
|
||||
mkdir -p artifacts
|
||||
|
||||
- | # Install Pre-req packages
|
||||
apt update;
|
||||
|
||||
@ -19,12 +22,29 @@ variables:
|
||||
git;
|
||||
|
||||
# ToDo: Install python deps
|
||||
# commitizen
|
||||
- |
|
||||
pip install \
|
||||
commitizen==3.14.1
|
||||
|
||||
- | # setup git user
|
||||
git config --global user.email "helpdesk@nofusscomputing.com";
|
||||
git config --global user.name "nfc_bot";
|
||||
|
||||
- | # Update origin using gitlab token
|
||||
echo "Current git origin";
|
||||
|
||||
git remote -v;
|
||||
|
||||
git remote remove origin;
|
||||
|
||||
echo "Removed origin";
|
||||
|
||||
git remote add origin https://gitlab-ci-token:$GIT_COMMIT_TOKEN@gitlab.com/$CI_PROJECT_PATH.git;
|
||||
|
||||
echo "Add origin with auth";
|
||||
|
||||
git remote -v;
|
||||
|
||||
- | # fetch repo details
|
||||
git fetch -fpv;
|
||||
|
||||
@ -32,10 +52,18 @@ variables:
|
||||
git switch development;
|
||||
|
||||
- | # pull dev branch
|
||||
git pull development --rebase
|
||||
git pull origin development --rebase
|
||||
|
||||
- | # Init git sub-modules
|
||||
git submodule update --init
|
||||
|
||||
|
||||
script:
|
||||
|
||||
|
||||
- | # Store old version number
|
||||
export OLD_VERSION=$(cz version --project) # old ver
|
||||
export OLD_VERSION=$(cz version --project);
|
||||
echo "Trace - OLD_VERSION[$OLD_VERSION]"
|
||||
|
||||
# rc codes https://commitizen-tools.github.io/commitizen/exit_codes/
|
||||
- | # Bump the version
|
||||
@ -58,11 +86,15 @@ variables:
|
||||
|
||||
fi;
|
||||
|
||||
echo "Trace - VERSION_BUMPED[$VERSION_BUMPED]"
|
||||
|
||||
- | # Store new version number
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
export NEW_VERSION=$(cz version --project)
|
||||
|
||||
echo "Trace - NEW_VERSION[$NEW_VERSION]"
|
||||
|
||||
fi;
|
||||
|
||||
- | # git stage .cz.yaml
|
||||
@ -70,6 +102,10 @@ variables:
|
||||
|
||||
git add .cz.yaml;
|
||||
|
||||
echo "git staged .cz.yaml";
|
||||
|
||||
git status;
|
||||
|
||||
fi;
|
||||
|
||||
- | # Update version in galaxy file
|
||||
@ -84,16 +120,26 @@ variables:
|
||||
|
||||
git add galaxy.yml
|
||||
|
||||
echo "git staged galaxy.yml";
|
||||
|
||||
git status;
|
||||
|
||||
fi;
|
||||
|
||||
- | # changelog since last version - for development branch
|
||||
echo "changelog since last version - for development branch";
|
||||
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
cz changelog --incremental --dry-run > artifacts/incremental_changelog.txt
|
||||
|
||||
ls -lR artifacts/
|
||||
|
||||
fi;
|
||||
|
||||
- | # store incremental changelog since last version
|
||||
echo "store incremental changelog since last version";
|
||||
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
curl \
|
||||
@ -104,6 +150,8 @@ variables:
|
||||
fi;
|
||||
|
||||
- | # complete changelog since last normal release - for master branch
|
||||
echo "complete changelog since last normal release - for master branch";
|
||||
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
cz changelog --merge-prerelease --dry-run > artifacts/full_changelog.txt
|
||||
@ -140,37 +188,74 @@ variables:
|
||||
|
||||
fi;
|
||||
|
||||
- | # Create release notes
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
if [ $CI_COMMIT_BRANCH == "development" ]; then
|
||||
|
||||
cp artifacts/incremental_changelog.txt artifacts/release_notes.md
|
||||
|
||||
elif [ $CI_COMMIT_BRANCH == "master" ]; then
|
||||
|
||||
cp artifacts/full_changelog.txt artifacts/release_notes.md
|
||||
|
||||
else
|
||||
|
||||
echo "This job should only run on 'development' and 'master' branches";
|
||||
exit 1;
|
||||
|
||||
fi;
|
||||
|
||||
fi;
|
||||
|
||||
- | # Store Release notes
|
||||
curl \
|
||||
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
|
||||
--upload-file artifacts/release_notes.md \
|
||||
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${NEW_VERSION}/release_notes.md";
|
||||
|
||||
- | # git stage CHANGELOG.md
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
git add CHANGELOG.md;
|
||||
|
||||
echo "git staged CHANGELOG.md";
|
||||
|
||||
git status;
|
||||
|
||||
fi;
|
||||
|
||||
|
||||
script:
|
||||
|
||||
|
||||
- | # user overridable section for custom actions before commit and push
|
||||
echo "if you need to add/edit files to be commited as part of the release, override the 'script:' section of the job with your custom commands"
|
||||
|
||||
|
||||
after_script:
|
||||
|
||||
- | # commit any changes
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
cat <<EOF | git commit -F-
|
||||
build: bump version ${OLD_VERSION} -> ${NEW_VERSION}
|
||||
git status;
|
||||
|
||||
!${CI_MERGE_REQUEST_IID}
|
||||
EOF
|
||||
echo "commit changes to repo"
|
||||
|
||||
cat <<EOF | git commit -F-
|
||||
build: bump version ${OLD_VERSION} -> ${NEW_VERSION}
|
||||
|
||||
!${CI_MERGE_REQUEST_IID}
|
||||
EOF
|
||||
|
||||
fi;
|
||||
|
||||
- | # Store the changes commit for the tag
|
||||
export CHANGE_COMMIT=$(git log -n1 --format=format:"%H")
|
||||
|
||||
echo "Trace - CHANGE_COMMIT[$CHANGE_COMMIT]"
|
||||
|
||||
if [ "${CI_COMMIT_SHA}" == "${CHANGE_COMMIT}" ]; then
|
||||
|
||||
echo "No changes appear to have been commited!"
|
||||
|
||||
exit 1;
|
||||
|
||||
fi;
|
||||
|
||||
git log -3;
|
||||
|
||||
|
||||
- | # push development to origin
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
@ -193,19 +278,19 @@ variables:
|
||||
- | # store metadata for use in later stages
|
||||
if [ "0$VERSION_BUMPED" == "00" ]; then
|
||||
|
||||
cat <<EOF > artifacts/vars.env
|
||||
cat <<EOF > artifacts/metadata.env
|
||||
|
||||
export CHANGE_COMMIT=${CHANGE_COMMIT}
|
||||
export CHANGE_COMMIT=${CHANGE_COMMIT}
|
||||
|
||||
export NEW_VERSION=${NEW_VERSION}
|
||||
export NEW_VERSION=${NEW_VERSION}
|
||||
|
||||
export OLD_VERSION=${CURRENT_VERSION}
|
||||
export OLD_VERSION=${CURRENT_VERSION}
|
||||
|
||||
export VERSION_BUMPED=${VERSION_BUMPED}
|
||||
export VERSION_BUMPED=${VERSION_BUMPED}
|
||||
|
||||
EOF;
|
||||
EOF
|
||||
|
||||
chmod +x artifacts/vars.env;
|
||||
chmod +x artifacts/metadata.env;
|
||||
|
||||
curl \
|
||||
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
|
||||
@ -227,23 +312,30 @@ variables:
|
||||
git push --tags
|
||||
|
||||
fi;
|
||||
|
||||
artifacts:
|
||||
untracked: false
|
||||
when: on_success
|
||||
when: always
|
||||
expire_in: "3 days"
|
||||
paths:
|
||||
- "artifacts/*"
|
||||
rules:
|
||||
|
||||
- if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
|
||||
when: never
|
||||
|
||||
- if: $CI_COMMIT_BRANCH
|
||||
when: always
|
||||
|
||||
- if: # Occur on merge
|
||||
$CI_COMMIT_BRANCH == "development"
|
||||
and
|
||||
&&
|
||||
$CI_PIPELINE_SOURCE == "push"
|
||||
when: manual
|
||||
|
||||
- if: # Occur on merge
|
||||
$CI_COMMIT_BRANCH == "master"
|
||||
and
|
||||
&&
|
||||
$CI_PIPELINE_SOURCE == "push"
|
||||
when: always
|
||||
|
||||
@ -260,29 +352,30 @@ variables:
|
||||
|
||||
if [ "0$ANSIBLE_GALAXY_UPLOAD_TOKEN" == "0" ]; then
|
||||
|
||||
echo No galaxy token within vars;
|
||||
echo variable ANSIBLE_GALAXY_UPLOAD_TOKEN must be set;
|
||||
exit 1;
|
||||
|
||||
fi;
|
||||
|
||||
if [ "0$ANSIBLE_GALAXY_NAMESPACE" == "0" ]; then
|
||||
|
||||
echo No galaxy token within vars;
|
||||
echo variable ANSIBLE_GALAXY_NAMESPACE must be set;
|
||||
exit 1;
|
||||
|
||||
fi;
|
||||
|
||||
if [ "0$ANSIBLE_GALAXY_PACKAGE_NAME" == "0" ]; then
|
||||
|
||||
echo No galaxy token within vars;
|
||||
echo variable ANSIBLE_GALAXY_PACKAGE_NAME must be set;
|
||||
exit 1;
|
||||
|
||||
fi;
|
||||
|
||||
fi
|
||||
|
||||
# ToDo: install python deps
|
||||
# for galaxy build
|
||||
- | # Install python deps
|
||||
pip install \
|
||||
ansible==9.2.0
|
||||
|
||||
script:
|
||||
|
||||
@ -297,21 +390,24 @@ variables:
|
||||
- "artifacts/*"
|
||||
rules:
|
||||
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: on_success
|
||||
|
||||
- if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
|
||||
when: never
|
||||
|
||||
- if:
|
||||
$CI_COMMIT_BRANCH != "development"
|
||||
and
|
||||
&&
|
||||
$CI_COMMIT_BRANCH != "master"
|
||||
and
|
||||
&&
|
||||
$CI_PIPELINE_SOURCE == "push"
|
||||
when: always
|
||||
|
||||
- if: $CI_COMMIT_TAG != ""
|
||||
when: always
|
||||
|
||||
- when: never
|
||||
|
||||
|
||||
|
||||
# store built package in generic package registry
|
||||
.ansible_collection_stage_package:
|
||||
stage: prepare
|
||||
@ -322,11 +418,24 @@ variables:
|
||||
name: Gitlab Package Registry
|
||||
url: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/
|
||||
script:
|
||||
- |
|
||||
- | # Store collection
|
||||
curl \
|
||||
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
|
||||
--upload-file artifacts/galaxy/$(ls artifacts/galaxy/) \
|
||||
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/collection.tar.gz"
|
||||
--upload-file artifacts/galaxy/${ANSIBLE_GALAXY_NAMESPACE}-${ANSIBLE_GALAXY_PACKAGE_NAME}-${CI_COMMIT_TAG}.tar.gz \
|
||||
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/${ANSIBLE_GALAXY_NAMESPACE}-${ANSIBLE_GALAXY_PACKAGE_NAME}-${CI_COMMIT_TAG}.tar.gz"
|
||||
|
||||
- | # Fetch Release Notes
|
||||
mkdir -p artifacts;
|
||||
|
||||
curl \
|
||||
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
|
||||
-o artifacts/release_notes.md \
|
||||
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${NEW_VERSION}/release_notes.md
|
||||
|
||||
echo "Release notes fetched";
|
||||
|
||||
ls -lR artifacts/
|
||||
|
||||
artifacts:
|
||||
untracked: false
|
||||
when: on_success
|
||||
@ -335,7 +444,7 @@ variables:
|
||||
- "artifacts/*"
|
||||
rules:
|
||||
|
||||
- if: $CI_COMMIT_TAG != ""
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: on_success
|
||||
|
||||
- when: never
|
||||
@ -349,14 +458,26 @@ variables:
|
||||
GIT_STRATEGY: none
|
||||
script:
|
||||
|
||||
# ToDo: use gitlab release container to create release
|
||||
# add galaxy link release url for the version
|
||||
- ls -lR artifacts/
|
||||
|
||||
artifacts:
|
||||
when: never
|
||||
release:
|
||||
tag_name: $CI_COMMIT_TAG
|
||||
description: ./artifacts/release_notes.md
|
||||
name: $CI_COMMIT_TAG
|
||||
assets:
|
||||
links:
|
||||
- name: 'Ansible Galaxy'
|
||||
url: https://galaxy.ansible.com/ui/repo/published/${ANSIBLE_GALAXY_NAMESPACE}/${ANSIBLE_GALAXY_PACKAGE_NAME}/?version=${CI_COMMIT_TAG}
|
||||
- name: ${ANSIBLE_GALAXY_NAMESPACE}-${ANSIBLE_GALAXY_PACKAGE_NAME}-${CI_COMMIT_TAG}.tar.gz
|
||||
url: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/${ANSIBLE_GALAXY_NAMESPACE}-${ANSIBLE_GALAXY_PACKAGE_NAME}-${CI_COMMIT_TAG}.tar.gz
|
||||
link_type: package
|
||||
- name: Documentation
|
||||
url: https://nofusscomputing.com/projects/ansible/collections/${ANSIBLE_GALAXY_PACKAGE_NAME}
|
||||
milestones:
|
||||
- $CI_MERGE_REQUEST_MILESTONE
|
||||
rules:
|
||||
|
||||
- if: $CI_COMMIT_TAG != ""
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: on_success
|
||||
|
||||
- when: never
|
||||
@ -374,24 +495,36 @@ variables:
|
||||
url: https://galaxy.ansible.com/ui/repo/published/${ANSIBLE_GALAXY_NAMESPACE}/${ANSIBLE_GALAXY_PACKAGE_NAME}/
|
||||
before_script:
|
||||
|
||||
# ToDo: install required deps
|
||||
- | # Install python deps
|
||||
pip install \
|
||||
ansible
|
||||
|
||||
- | # Download Staged package
|
||||
wget \
|
||||
--header="JOB-TOKEN: $CI_JOB_TOKEN" \
|
||||
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/collection.tar.gz"
|
||||
pip list;
|
||||
|
||||
- | # Prepare filename for package
|
||||
# mkdir -p artifacts/galaxy;
|
||||
|
||||
# mv collection.tar.gz artifacts/galaxy/${ANSIBLE_GALAXY_NAMESPACE}-${ANSIBLE_GALAXY_PACKAGE_NAME}-${CI_COMMIT_TAG}.tar.gz
|
||||
|
||||
# echo "Prepare filename to be in the correct format";
|
||||
|
||||
ls -lR artifacts;
|
||||
|
||||
script:
|
||||
- | # Publish package to Ansible Galaxy
|
||||
ansible-galaxy collection publish \
|
||||
--server $(ANSIBLE_GALAXY_SERVER_URL) \
|
||||
--token $(ANSIBLE_GALAXY_UPLOAD_TOKEN) \
|
||||
--verbose collection.tar.gz
|
||||
--server ${ANSIBLE_GALAXY_SERVER_URL} \
|
||||
--token ${ANSIBLE_GALAXY_UPLOAD_TOKEN} \
|
||||
--verbose artifacts/galaxy/${ANSIBLE_GALAXY_NAMESPACE}-${ANSIBLE_GALAXY_PACKAGE_NAME}-${CI_COMMIT_TAG}.tar.gz
|
||||
artifacts:
|
||||
when: never
|
||||
untracked: false
|
||||
when: on_success
|
||||
expire_in: "3 days"
|
||||
paths:
|
||||
- "artifacts/*"
|
||||
rules:
|
||||
|
||||
- if: $CI_COMMIT_TAG != ""
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: on_success
|
||||
|
||||
- when: never
|
Reference in New Issue
Block a user