-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add files for pipeline to push to galaxy (#1)
* Add files for pipeline to push to galaxy * Lint issues
- Loading branch information
1 parent
4c1ef2a
commit f033f07
Showing
5 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# .github/workflows/ansible-lint.yml | ||
name: ansible-lint | ||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
jobs: | ||
build: | ||
name: Ansible Lint # Naming the build is important to use it as a status check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run ansible-lint | ||
uses: ansible/ansible-lint@main # or version tag instead of 'main' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | ||
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-core-${{ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | ||
git add . | ||
git commit -m "Update CHANGELOG.md" | ||
git push origin HEAD:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ readme: README.md | |
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url) | ||
# @nicks:irc/im.site#channel' | ||
authors: | ||
- Itential <[email protected]> | ||
- Itential <[email protected]> | ||
|
||
### OPTIONAL but strongly recommended | ||
# A short summary description of the collection | ||
|
@@ -29,19 +29,20 @@ description: | | |
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only | ||
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file' | ||
license: | ||
- GPL-3.0-or-later | ||
- GPL-3.0-or-later | ||
|
||
# The path to the license file for the collection. This path is relative to the root of the collection. This key is | ||
# mutually exclusive with 'license' | ||
#license_file: '' | ||
# license_file: '' | ||
|
||
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character | ||
# requirements as 'namespace' and 'name' | ||
tags: | ||
- itential | ||
- automation | ||
- gateway | ||
- core | ||
- itential | ||
- automation | ||
- gateway | ||
- core | ||
- tools | ||
|
||
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the | ||
# collection label 'namespace.name'. The value is a version range | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.core/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.core/compare/' + tags[i-1] + '...' + release | ||
print('Full Changelog:', full, '\n\n') |