-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (58 loc) · 1.85 KB
/
build.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
name: "Ansible collection build"
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
jobs:
build:
name: Build and publish
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version from Git tag
id: ref
run: |
type=$(printf "%s" "$GITHUB_REF" | cut -d '/' -f 2)
if [ "$type" = "tags" ]; then
tag=$(printf "%s" "$GITHUB_REF" | cut -d '/' -f 3)
version=$(printf "%s" "$tag" | tr -d 'v')
if ! printf "%s" "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
printf "Version %s is invalid\\n"
exit 1
else
echo "tag=${tag}" >> $GITHUB_OUTPUT
echo "version=${version}" >> $GITHUB_OUTPUT
fi
else
printf "Ref type %s is invalid for this workflow\\n" "$type"
exit 1
fi
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Ansible and dependencies
run: pip install ansible pyyaml
- name: Populate collection version
run: python galaxy.py
env:
GALAXY_VERSION: ${{ steps.ref.outputs.version }}
- name: Configure Ansible
run: |
printf "[galaxy]\\n\
server_list = release\\n\\n\
[galaxy_server.release]\\n\
url = https://galaxy.ansible.com/api/\\n\
token = %s\\n" \
"$GALAXY_TOKEN" > "${HOME}/.ansible.cfg"
env:
GALAXY_TOKEN: ${{ secrets.GALAXY_TOKEN }}
- name: Build collection
run: ansible-galaxy collection build
- name: Publish collection
run: ansible-galaxy collection publish *"$GALAXY_VERSION".tar.gz
env:
GALAXY_VERSION: ${{ steps.ref.outputs.version }}