Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ansible-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ jobs:
- uses: actions/checkout@v4
- name: Run ansible-lint
uses: ansible/ansible-lint@main
with:
args: "--exclude .ansible"
requirements_file: "requirements.yml"
64 changes: 64 additions & 0 deletions .github/workflows/publish_ansible_collection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Publish Ansible Galaxy Collection

on:
release:
types: [published]
workflow_dispatch:

jobs:
publish-collection:
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Install Ansible
run: pip install ansible

- name: Determine Ansible Galaxy version
run: echo "GALAXY_VERSION=$(echo ${{ github.ref_name }} | cut -c2-)" >> $GITHUB_ENV

- name: Update Ansible Galaxy version
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git checkout main
echo "Updating version to ${{ env.GALAXY_VERSION }} in galaxy.yml"
sed -i 's/\(version:\) .*/\1 ${{ env.GALAXY_VERSION }}/g' galaxy.yml
git add galaxy.yml

- name: Update changelog
run: |
python scripts/changelog.py > CHANGELOG.md
git add CHANGELOG.md

- name: Commit changes
run: |
git commit -m "Update galaxy version and changelog for release ${{ env.GALAXY_VERSION }} [skip ci]"
git push origin HEAD:main

- name: Update release tag
run: |
git pull
git tag -f ${{ github.ref_name }}
git push origin HEAD:main
git push origin -f ${{ github.ref_name }}

- name: Build Ansible collection
run: ansible-galaxy collection build

- name: Determine Ansible collection archive name
run: echo "ARTIFACT=itential-toolkit-${{ env.GALAXY_VERSION }}.tar.gz" >> $GITHUB_ENV

- name: Publish collection to Ansible Galaxy
env:
ANSIBLE_API_TOKEN: ${{ secrets.ANSIBLE_API_TOKEN }}
run: ansible-galaxy collection publish ${{ env.ARTIFACT }} --token $ANSIBLE_API_TOKEN
30 changes: 30 additions & 0 deletions .github/workflows/updateChangelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run changelog Script

on:
release:
types: [published]
workflow_dispatch:

jobs:
updateChangelog:
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup python
uses: actions/setup-python@v5
with:
python-version: 3.8 #install the python needed
- name: Install dependencies
run: |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: execute py script
run: |
python scripts/changelog.py > CHANGELOG.md
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Update CHANGELOG.md"
git push origin HEAD:main
5 changes: 4 additions & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ readme: README.md
authors:
- Steven Schattenberg <steven.schattenberg@itential.com>
- Ranjitha Parameshwaraiah <ranjitha.parameshwaraiah@itential.com>
- Wade Stern <wade.stern@itential.com>


### OPTIONAL but strongly recommended
Expand All @@ -44,7 +45,9 @@ tags:
# collection label 'namespace.name'. The value is a version range
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
# range specifiers can be set and are separated by ','
dependencies: {}
dependencies:
itential.platform: "*"
community.mongodb: "*"

# The URL of the originating SCM repository
repository: http://example.com/repository
Expand Down
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collections:
- name: itential.platform
- name: community.mongodb
92 changes: 92 additions & 0 deletions scripts/changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python3

"""changelog
This script outputs a changelog markdown to stdout.
"""

import subprocess
import re

# Get all the tags for the project
git_tag_result = subprocess.run(
["git", "tag"], capture_output=True, text=True
)

# Make a tag list
tags = git_tag_result.stdout.split("\n")

# Remove v from tags
for i in range(len(tags)):
tags[i] = tags[i].replace('v','')

# Remove empty strings from tags
tags[:] = [x for x in tags if x]

# Sort tags by semver number
tags.sort(key = lambda x: [int(y) for y in x.split('.')])

# Add v back into tags
for i in range(len(tags)):
tags[i] = 'v'+tags[i]

# Iterate through all the tags in the tag list and get a list of commits
count = 0
changelogs = {}
for tag in tags:
if tag:
if count == 0:
# If this is the first tag, get a list of the commits up to when the tag was created.
git_log_result = subprocess.getoutput(
f'git log --pretty=oneline {tag} | grep -v Merge | cut -d " " -f 2-'
)
else:
# For subsequents tags, get a list of the commits since the previous tag.
git_log_result = subprocess.getoutput(
f'git log --pretty=oneline {tag}...{prev_tag} | grep -v Merge | cut -d " " -f 2-'
)

# Convert the commit list to a set and then back to a list to remove any duplicate commits.
git_logs = list(set(git_log_result.split('\n')))

# Sort git_logs so they are in the same order each time
git_logs.sort()

# Add links to pull requests
for i in range(len(git_logs)):
if re.search(r'\(\#\d*\)',git_logs[i]):
test = re.search(r'\(\#\d*\)',git_logs[i])
num = test.group()
num = num[2:]
num = num[:-1]
sub = ' https://github.com/itential/itential.toolkit/pull/' + num
git_logs[i] = re.sub('\(\#\d*\)',sub,git_logs[i])

# Add the commits to the changelogs dictionary using the tag as the key and the
# commit list as the value
changelogs[tag] = git_logs

# Save the tag as the previous tag and increment the counter
prev_tag = tag
count = count + 1

# Create the changelog markdown output
print('# Changelog\n')
for release,changes in reversed(changelogs.items()):
# Get the tag date in the date format we want
release_date = subprocess.getoutput(
f'git log -1 --format=%ad --date=format:"%B %d, %Y" {release}'
)

# Print the tag (release) and the date it was created
print(f'## {release} ({release_date})\n')

# Print an unordered list of the commits (changes)
for change in changes:
print(f'* {change}')
print()

for i in range(len(tags)):
if i > 0:
if release == tags[i]:
full = 'https://github.com/itential/itential.toolkit/compare/' + tags[i-1] + '...' + release
print('Full Changelog:', full, '\n\n')