-
Notifications
You must be signed in to change notification settings - Fork 17
98 lines (91 loc) · 3.68 KB
/
publish_collection.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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 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