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

Allow to provide Galaxy importer configuration; add tests #2

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

name: Action testing

'on':
push:
branches: [main]
pull_request:
branches: [main]
# Run once per week (Friday at 07:00 UTC)
schedule:
- cron: '0 7 * * 5'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
with:
# This should **NOT** be the Python version used for the action itself
python-version: 3.12

- name: Install ansible-core
run: pip install ansible-core

- name: Build collection
run: |
ansible-galaxy collection build
mv foo-bar-1.2.3.tar.gz ..
ls -lah ..
working-directory: tests/foo.bar

- name: Run action
id: action
uses: ./
with:
artifact-path: tests/foo-bar-1.2.3.tar.gz
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
# GitHub Action for testing importing an Ansible collection with the Galaxy importer

[![Linting](https://github.com/ansible-community/github-action-test-galaxy-import/actions/workflows/linting.yml/badge.svg)](https://github.com/ansible-community/github-action-test-galaxy-import/actions/workflows/linting.yml)
[![Tests](https://github.com/ansible-community/github-action-test-galaxy-import/actions/workflows/tests.yml/badge.svg)](https://github.com/ansible-community/github-action-test-galaxy-import/actions/workflows/tests.yml)
[![REUSE](https://github.com/ansible-community/github-action-test-galaxy-import/actions/workflows/reuse.yml/badge.svg)](https://github.com/ansible-community/github-action-test-galaxy-import/actions/workflows/reuse.yml)

A composite GitHub Action that allows to test importing a built Ansible collection with the [Galaxy importer](https://github.com/ansible/galaxy-importer) in GitHub Actions CI/CD workflows.
Expand All @@ -30,6 +31,12 @@ To use the action, add the following step to your workflow file (for example `.g

The follow options can be provided to this GitHub Action.

### `artifact-path`

Path to the collection's build artifact (tarball).

**(REQUIRED)**

### `python-version`

The Python version to use.
Expand All @@ -49,11 +56,10 @@ This is assumed to exist in https://github.com/ansible/ansible.

Path to a Galaxy requirements file. If present, these collections will be installed.

### `artifact-path`
### `importer-config-path`

Path to the collection's build artifact (tarball).

**(REQUIRED)**
Path to a Galaxy importer configuration file.
See https://github.com/ansible/galaxy-importer#configuration for more information.

## Bundled shared workflow

Expand Down
37 changes: 33 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: >-
This action tries to import a built Ansible collection artifact with the Ansible Galaxy importer.
author: "Felix Fontein (@felixfontein)"
inputs:
artifact-path:
description: >-
Path to the collection's build artifact (tarball).
required: true
python-version:
description: |-
The Python version to use.
Expand All @@ -22,10 +26,10 @@ inputs:
collection-requirements-path:
description: >-
Path to a Galaxy requirements file. If present, these collections will be installed.
artifact-path:
importer-config-path:
description: >-
Path to the collection's build artifact (tarball).
required: true
Path to a Galaxy importer configuration file.
See https://github.com/ansible/galaxy-importer#configuration for more information.
runs:
using: composite
steps:
Expand Down Expand Up @@ -53,12 +57,37 @@ runs:
run: |
ansible-galaxy collection install --pre --requirements-file "${COLLECTION_REQUIREMENTS_PATH}"

- name: Preparations
id: preparations
env:
ARTIFACT_PATH: ${{ inputs.artifact-path }}
IMPORTER_CONFIG_PATH: ${{ inputs.importer-config-path }}
shell: python
run: |
# Preparations

import os
import shlex

def set_output(name, value):
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as f:
f.write(f'{name}={value}{os.linesep}')

artifact_path = os.environ['ARTIFACT_PATH']
importer_config_path = os.environ['IMPORTER_CONFIG_PATH']

command = ['python', '-m', 'galaxy_importer.main', artifact_path]
if importer_config_path:
command.insert(0, f'GALAXY_IMPORTER_CONFIG={importer_config_path}')

set_output('command', shlex.join(command))

- name: Run Galaxy importer
shell: bash
env:
ARTIFACT_PATH: ${{ inputs.artifact-path }}
run: |
python -m galaxy_importer.main "${ARTIFACT_PATH}" | tee import.log
${{ steps.preparations.outputs.command }} | tee import.log

- name: Analyze result
shell: python
Expand Down
9 changes: 9 additions & 0 deletions tests/foo.bar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
Copyright (c) Ansible Project
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later
-->

# Hello

Nothing to see.
17 changes: 17 additions & 0 deletions tests/foo.bar/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

namespace: foo
name: bar
version: 1.2.3
readme: README.md
authors:
- Nobody
license:
- GPL-3.0-or-later
tags:
- test
repository: https://github.com/ansible-community/github-action-test-galaxy-import/
issues: https://github.com/ansible-community/github-action-test-galaxy-import/issues/
6 changes: 6 additions & 0 deletions tests/foo.bar/meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

requires_ansible: '>=2.9.10'