[stable-1] Use import galaxy workflow from ansible-collections/community.docker#754 #687
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: import-galaxy | |
'on': | |
# Run CI against all pushes (direct commits, also merged PRs) to main, and all Pull Requests | |
push: | |
branches: | |
- main | |
- stable-* | |
pull_request: | |
jobs: | |
build-collection: | |
name: Build collection artifact | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
path: ./checkout | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.10' | |
- name: Install ansible-core | |
run: pip install https://github.com/ansible/ansible/archive/stable-2.12.tar.gz --disable-pip-version-check | |
- name: Make sure galaxy.yml has version entry | |
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 | |
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@v3 | |
with: | |
name: collection-build-${{ github.sha }} | |
path: ./artifact/ | |
import-galaxy: | |
name: Import artifact with Galaxy importer | |
runs-on: ubuntu-latest | |
needs: | |
- build-collection | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.10' | |
- name: Install ansible-core | |
run: pip install https://github.com/ansible/ansible/archive/stable-2.12.tar.gz --disable-pip-version-check | |
- name: Install galaxy-importer | |
run: pip install galaxy-importer --disable-pip-version-check | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
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 *-*-*.tar.gz |