Publish fedora.linux_system_roles collection to Ansible Galaxy #815
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
name: Publish fedora.linux_system_roles collection to Ansible Galaxy | |
on: | |
workflow_dispatch: | |
schedule: | |
# Run daily at 01:37 UTC | |
- cron: '37 1 * * *' | |
jobs: | |
publish_collection: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout auto-maintenance repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_PUSH_TOKEN }} | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
- name: Install dependencies | |
shell: bash | |
run: | | |
set -euxo pipefail | |
sudo apt-get update | |
sudo apt install pandoc | |
pip install --upgrade pip | |
pip install --upgrade ansible-core galaxy-importer pypandoc rst2html 'zipp>=3.1.0' 'pyyaml<6,>=5.4.1' markdown | |
docker --version | |
- name: Build and publish the collection | |
shell: bash | |
id: build | |
run: | | |
set -euxo pipefail | |
OLDVER=$(python3 ./get_collection_version.py) | |
echo ::debug::"Old collection version is $OLDVER" | |
# Ensure there is no dest_path before running release_collection.py | |
dest_path=/var/tmp/collection | |
rm -rf "$dest_path" | |
echo ::group::Build Collection | |
python3 ./release_collection.py --debug --save-current-changelog --dest-path "$dest_path" | |
echo ::endgroup:: | |
NEWVER=$(python3 ./get_collection_version.py) | |
# We are up to date - exit | |
if git diff --quiet; then | |
echo ::info No roles have new releases - no collection will be published | |
echo "updated=0" >> $GITHUB_OUTPUT | |
exit 0 | |
elif [ "$OLDVER" == "$NEWVER" ]; then | |
echo ::error::"Collection version $OLDVER has not changed" | |
exit 1 | |
else | |
echo ::debug::"New collection version $NEWVER will be released" | |
fi | |
# A new collection has been build - find the tarball | |
_tarball="$dest_path/fedora-linux_system_roles-$NEWVER.tar.gz" | |
if [ ! -f "${_tarball}" ]; then | |
echo ::error::"Did not find tarball to publish: ${_tarball}" | |
exit 1 | |
fi | |
# Push the updated collection files | |
echo ::group::Push updates | |
git config user.name systemroller | |
git config user.email "systemroller@users.noreply.github.com" | |
git commit -a -m "Collection version was updated" | |
git push | |
echo ::endgroup:: | |
# Publish the collection. This step should | |
# be last since the previous steps must succeed | |
echo ::group::Publish Collection to Galaxy | |
ansible-galaxy collection publish -vv --token "${{ secrets.GALAXY_API_KEY }}" "$_tarball" | |
echo ::endgroup:: | |
echo ::info Done | |
echo "commit=$(git show -s --format=format:%H)" >> $GITHUB_OUTPUT | |
echo "tagname=$NEWVER" >> $GITHUB_OUTPUT | |
echo "updated=1" >> $GITHUB_OUTPUT | |
- name: Create tag | |
if: ${{ steps.build.outputs.updated == 1 }} | |
uses: mathieudutour/github-tag-action@v6.2 | |
with: | |
commit_sha: ${{ steps.build.outputs.commit }} | |
github_token: ${{ secrets.GH_PUSH_TOKEN }} | |
custom_tag: ${{ steps.build.outputs.tagname }} | |
tag_prefix: '' | |
- name: Create Release | |
id: create_release | |
if: ${{ steps.build.outputs.updated == 1 }} | |
uses: ncipollo/release-action@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag: ${{ steps.build.outputs.tagname }} | |
name: Version ${{ steps.build.outputs.tagname }} | |
bodyFile: ./CURRENT_VER_CHANGELOG.md | |
makeLatest: true |