Skip to content

Commit

Permalink
Use import galaxy workflow from ansible-collections/community.docker#754
Browse files Browse the repository at this point in the history
.
  • Loading branch information
felixfontein committed Jan 13, 2024
1 parent 56ce47a commit 359227b
Showing 1 changed file with 66 additions and 24 deletions.
90 changes: 66 additions & 24 deletions .github/workflows/import-galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
# SPDX-License-Identifier: GPL-3.0-or-later

name: import-galaxy
on:
'on':
# Run CI against all pushes (direct commits, also merged PRs) to main, and all Pull Requests
push:
branches:
- main
- stable-*
pull_request:

env:
# Adjust this to your collection
NAMESPACE: community
COLLECTION_NAME: routeros

jobs:
build-collection:
name: Build collection artifact
Expand All @@ -30,36 +25,66 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'

- name: Install ansible-core
- name: Install ansible-core devel
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

- name: Make sure galaxy.yml has version entry
run: >-
python -c
'import yaml ;
f = open("galaxy.yml", "rb") ;
data = yaml.safe_load(f) ;
f.close() ;
data["version"] = data.get("version") or "0.0.1" ;
f = open("galaxy.yml", "wb") ;
f.write(yaml.dump(data).encode("utf-8")) ;
f.close() ;
'
shell: python
id: collection-metadata
run: |
import os
import yaml
def set_output(name, value):
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as f:
f.write(f'{name}={value}{os.linesep}')
# Make sure galaxy.yml contains a version
with open('galaxy.yml', 'rb') as f:
data = yaml.safe_load(f) ;
data['version'] = data.get('version') or '0.0.1'
with open('galaxy.yml', 'w', encoding='utf-8') as f:
f.write(yaml.dump(data))
# Create Galaxy requirements file
if data.get('dependencies'):
reqs = dict(collections=[])
for collection, version in sorted(data['dependencies'].items()):
reqs['collections'].append(dict(
name=collection,
source='https://galaxy.ansible.com',
version=version,
))
with open('../requirements.yml', 'w', encoding='utf-8') as f:
f.write(yaml.dump(reqs))
# Extract namespace and collection name
set_output('name', data['name'])
set_output('namespace', data['namespace'])
set_output('version', data['version'])
set_output('filename', f"{data['namespace']}-{data['name']}-{data['version']}.tar.gz")
working-directory: ./checkout

- name: Build collection
run: ansible-galaxy collection build
working-directory: ./checkout

- name: Copy artifact into subdirectory
run: mkdir ./artifact && mv ./checkout/${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-*.tar.gz ./artifact
shell: bash
run: |
set -e
mkdir artifact
mv checkout/${{ steps.collection-metadata.outputs.filename }} artifact/
if [ -f requirements.yml ]; then
mv requirements.yml artifact/
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-${{ github.sha }}
name: collection-build-${{ github.sha }}
path: ./artifact/

import-galaxy:
Expand All @@ -71,9 +96,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
# Currently requirements-parser is incompatible with Python 3.12
# (https://github.com/madpah/requirements-parser/issues/88), so we
# have to stick to Python 3.11 for now...
python-version: '3.11'

- name: Install ansible-core
- name: Install ansible-core devel
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

- name: Install galaxy-importer
Expand All @@ -82,7 +110,21 @@ jobs:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-${{ github.sha }}
name: collection-build-${{ github.sha }}

- name: List files
shell: bash
run: |
ls -la
- name: Install collection dependencies
shell: bash
run: |
if [ -f requirements.yml ]; then
ansible-galaxy collection install --pre --requirements-file requirements.yml
else
echo "Collection has no dependencies."
fi
- name: Run Galaxy importer
run: python -m galaxy_importer.main ${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}-*.tar.gz
run: python -m galaxy_importer.main *-*-*.tar.gz

0 comments on commit 359227b

Please sign in to comment.