Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Galaxy deploy collection #216

Merged
merged 8 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Release

"on":
push:
branches:
- main
# branches:
# - main

jobs:
release:
Expand Down Expand Up @@ -38,17 +38,22 @@ jobs:
with:
tag-template: "{VERSION}"
version-command: |
cat current-version.txt
cat galaxy.yml|grep version:|cut -d' ' -f2
staticdev marked this conversation as resolved.
Show resolved Hide resolved

- name: Install Ansible
run: |
pip install --constraint=.github/workflows/constraints.txt ansible

- name: Trigger a new import on Galaxy.
- name: Release to Ansible Galaxy.
env:
ANSIBLE_GALAXY_TOKEN: ${{ secrets.GALAXY_TOKEN }}
run: >-
ansible-galaxy role import
--api-key ${{ secrets.GALAXY_TOKEN }} $(echo ${{ github.repository }}
| cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
ansible-playbook -i 'localhost,' galaxy-deploy.yml
-e "github_tag=${{ github.ref }}"
-e "namespace=$(echo ${{ github.repository }}
| cut -d/ -f1)"
-e "collection=$(echo ${{ github.repository }}
| cut -d/ -f2)"
aalaesar marked this conversation as resolved.
Show resolved Hide resolved

- name: Publish the release notes
uses: release-drafter/release-drafter@v5
Expand Down
1 change: 0 additions & 1 deletion current-version.txt

This file was deleted.

50 changes: 50 additions & 0 deletions galaxy-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
# 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 }}"

- hosts: localhost
connection: local
gather_facts: false

vars:
# 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
staticdev marked this conversation as resolved.
Show resolved Hide resolved
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 }}"'
staticdev marked this conversation as resolved.
Show resolved Hide resolved

- name: Build the collection.
command: ansible-galaxy collection build

- name: Publish the collection.
command: >
ansible-galaxy collection publish ./{{ namespace }}-{{ collection }}-{{ release_tag }}.tar.gz
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace: aalaesar
name: nextcloud

# The version of the collection. Must be compatible with semantic versioning
version: 2.0.0
version: 1.9.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down