mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #7857/069b485b backport][stable-7] Use shared workflow for Galaxy import test (#7863)
Use shared workflow for Galaxy import test (#7857)
Simplifiy workflows.
(cherry picked from commit 069b485b7e
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
a3704353c9
commit
504759ce92
2 changed files with 6 additions and 121 deletions
118
.github/workflows/import-galaxy.yml
vendored
118
.github/workflows/import-galaxy.yml
vendored
|
@ -13,118 +13,8 @@ name: import-galaxy
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-collection:
|
|
||||||
name: Build collection artifact
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
path: ./checkout
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.12'
|
|
||||||
|
|
||||||
- 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
|
|
||||||
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@v4
|
|
||||||
with:
|
|
||||||
name: collection-build-${{ github.sha }}
|
|
||||||
path: ./artifact/
|
|
||||||
|
|
||||||
import-galaxy:
|
import-galaxy:
|
||||||
name: Import artifact with Galaxy importer
|
permissions:
|
||||||
runs-on: ubuntu-latest
|
contents: read
|
||||||
needs:
|
name: Test to import built collection artifact with Galaxy importer
|
||||||
- build-collection
|
uses: ansible-community/github-action-test-galaxy-import/.github/workflows/test-galaxy-import.yml@main
|
||||||
steps:
|
|
||||||
- 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 devel
|
|
||||||
run: pip install https://github.com/ansible/ansible/archive/devel.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@v4
|
|
||||||
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
|
|
||||||
|
|
9
.github/workflows/reuse.yml
vendored
9
.github/workflows/reuse.yml
vendored
|
@ -26,10 +26,5 @@ jobs:
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha || '' }}
|
ref: ${{ github.event.pull_request.head.sha || '' }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: REUSE Compliance Check
|
||||||
run: |
|
uses: fsfe/reuse-action@v2
|
||||||
pip install reuse
|
|
||||||
|
|
||||||
- name: Check REUSE compliance
|
|
||||||
run: |
|
|
||||||
reuse lint
|
|
||||||
|
|
Loading…
Reference in a new issue