forked from geerlingguy/ansible-collection-mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
galaxy-deploy.yml
55 lines (47 loc) · 1.56 KB
/
galaxy-deploy.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
---
# Automated release playbook for Ansible Collections.
#
# Originally based on Ericsysmin's 2020 blog post. Meant to be used in a GitHub
# Actions CI environment.
#
# Requires a ANSIBLE_GALAXY_TOKEN secret to be configured on the GitHub repo.
#
# Usage:
# ansible-playbook -i 'localhost,' galaxy-deploy.yml \
# -e "github_tag=${{ github.ref }}"
- name: Deploy new Collection version to Galaxy.
hosts: localhost
connection: local
gather_facts: false
vars:
namespace: geerlingguy
collection: mac
# Requires github_tag to be set when calling playbook.
release_tag: "{{ github_tag.split('/')[-1] }}"
pre_tasks:
- name: Ensure ANSIBLE_GALAXY_TOKEN is set.
fail:
msg: A valid ANSIBLE_GALAXY_TOKEN must be set.
when: "lookup('env', 'ANSIBLE_GALAXY_TOKEN') | length == 0"
- name: Ensure the ~/.ansible directory exists.
file:
path: ~/.ansible
state: directory
- name: Write the Galaxy token to ~/.ansible/galaxy_token
copy:
content: |
token: {{ lookup('env', 'ANSIBLE_GALAXY_TOKEN') }}
dest: ~/.ansible/galaxy_token
tasks:
- name: Ensure the galaxy.yml tag is up to date.
lineinfile:
path: galaxy.yml
regexp: "^version:"
line: 'version: "{{ release_tag }}"'
- name: Build the collection.
command: ansible-galaxy collection build
changed_when: true
- name: Publish the collection.
command: >
ansible-galaxy collection publish ./{{ namespace }}-{{ collection }}-{{ release_tag }}.tar.gz
changed_when: true