Skip to content

Commit 6a53550

Browse files
authored
Added files needed to push to galaxy (#6)
1 parent 9b1846f commit 6a53550

4 files changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Publish Ansible Galaxy Collection
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish-collection:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repo content
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
17+
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.8
22+
23+
- name: Install Ansible
24+
run: pip install ansible
25+
26+
- name: Determine Ansible Galaxy version
27+
run: echo "GALAXY_VERSION=$(echo ${{ github.ref_name }} | cut -c2-)" >> $GITHUB_ENV
28+
29+
- name: Update Ansible Galaxy version
30+
run: |
31+
git config user.name github-actions
32+
git config user.email github-actions@github.com
33+
git checkout main
34+
echo "Updating version to ${{ env.GALAXY_VERSION }} in galaxy.yml"
35+
sed -i 's/\(version:\) .*/\1 ${{ env.GALAXY_VERSION }}/g' galaxy.yml
36+
git add galaxy.yml
37+
38+
- name: Update changelog
39+
run: |
40+
python scripts/changelog.py > CHANGELOG.md
41+
git add CHANGELOG.md
42+
43+
- name: Commit changes
44+
run: |
45+
git commit -m "Update galaxy version and changelog for release ${{ env.GALAXY_VERSION }} [skip ci]"
46+
git push origin HEAD:main
47+
48+
- name: Update release tag
49+
run: |
50+
git pull
51+
git tag -f ${{ github.ref_name }}
52+
git push origin HEAD:main
53+
git push origin -f ${{ github.ref_name }}
54+
55+
- name: Build Ansible collection
56+
run: ansible-galaxy collection build
57+
58+
- name: Determine Ansible collection archive name
59+
run: echo "ARTIFACT=itential-platform-${{ env.GALAXY_VERSION }}.tar.gz" >> $GITHUB_ENV
60+
61+
- name: Publish collection to Ansible Galaxy
62+
env:
63+
ANSIBLE_API_TOKEN: ${{ secrets.ANSIBLE_API_TOKEN }}
64+
run: ansible-galaxy collection publish ${{ env.ARTIFACT }} --token $ANSIBLE_API_TOKEN
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run changelog Script
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
updateChangelog:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: checkout repo content
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: setup python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: 3.8 #install the python needed
20+
- name: Install dependencies
21+
run: |
22+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
23+
- name: execute py script
24+
run: |
25+
python scripts/changelog.py > CHANGELOG.md
26+
git config user.name github-actions
27+
git config user.email github-actions@github.com
28+
git add .
29+
git commit -m "Update CHANGELOG.md"
30+
git push origin HEAD:main

galaxy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ readme: README.md
1717
# @nicks:irc/im.site#channel'
1818
authors:
1919
- Itential <community@itential.com>
20+
- Wade Stern <wade.stern@itential.com>
2021

2122

2223
### OPTIONAL but strongly recommended

scripts/changelog.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python3
2+
3+
"""changelog
4+
This script outputs a changelog markdown to stdout.
5+
"""
6+
7+
import subprocess
8+
import re
9+
10+
# Get all the tags for the project
11+
git_tag_result = subprocess.run(
12+
["git", "tag"], capture_output=True, text=True
13+
)
14+
15+
# Make a tag list
16+
tags = git_tag_result.stdout.split("\n")
17+
18+
# Remove v from tags
19+
for i in range(len(tags)):
20+
tags[i] = tags[i].replace('v','')
21+
22+
# Remove empty strings from tags
23+
tags[:] = [x for x in tags if x]
24+
25+
# Sort tags by semver number
26+
tags.sort(key = lambda x: [int(y) for y in x.split('.')])
27+
28+
# Add v back into tags
29+
for i in range(len(tags)):
30+
tags[i] = 'v'+tags[i]
31+
32+
# Iterate through all the tags in the tag list and get a list of commits
33+
count = 0
34+
changelogs = {}
35+
for tag in tags:
36+
if tag:
37+
if count == 0:
38+
# If this is the first tag, get a list of the commits up to when the tag was created.
39+
git_log_result = subprocess.getoutput(
40+
f'git log --pretty=oneline {tag} | grep -v Merge | cut -d " " -f 2-'
41+
)
42+
else:
43+
# For subsequents tags, get a list of the commits since the previous tag.
44+
git_log_result = subprocess.getoutput(
45+
f'git log --pretty=oneline {tag}...{prev_tag} | grep -v Merge | cut -d " " -f 2-'
46+
)
47+
48+
# Convert the commit list to a set and then back to a list to remove any duplicate commits.
49+
git_logs = list(set(git_log_result.split('\n')))
50+
51+
# Sort git_logs so they are in the same order each time
52+
git_logs.sort()
53+
54+
# Add links to pull requests
55+
for i in range(len(git_logs)):
56+
if re.search(r'\(\#\d*\)',git_logs[i]):
57+
test = re.search(r'\(\#\d*\)',git_logs[i])
58+
num = test.group()
59+
num = num[2:]
60+
num = num[:-1]
61+
sub = ' https://github.com/itential/itential.platform/pull/' + num
62+
git_logs[i] = re.sub('\(\#\d*\)',sub,git_logs[i])
63+
64+
# Add the commits to the changelogs dictionary using the tag as the key and the
65+
# commit list as the value
66+
changelogs[tag] = git_logs
67+
68+
# Save the tag as the previous tag and increment the counter
69+
prev_tag = tag
70+
count = count + 1
71+
72+
# Create the changelog markdown output
73+
print('# Changelog\n')
74+
for release,changes in reversed(changelogs.items()):
75+
# Get the tag date in the date format we want
76+
release_date = subprocess.getoutput(
77+
f'git log -1 --format=%ad --date=format:"%B %d, %Y" {release}'
78+
)
79+
80+
# Print the tag (release) and the date it was created
81+
print(f'## {release} ({release_date})\n')
82+
83+
# Print an unordered list of the commits (changes)
84+
for change in changes:
85+
print(f'* {change}')
86+
print()
87+
88+
for i in range(len(tags)):
89+
if i > 0:
90+
if release == tags[i]:
91+
full = 'https://github.com/itential/itential.platform/compare/' + tags[i-1] + '...' + release
92+
print('Full Changelog:', full, '\n\n')

0 commit comments

Comments
 (0)