diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..14eee4a --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/README.md b/README.md index c70a8d8..2311dd8 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. @@ -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 diff --git a/action.yml b/action.yml index 8f0975a..dc87efa 100644 --- a/action.yml +++ b/action.yml @@ -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. @@ -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: @@ -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 diff --git a/tests/foo.bar/README.md b/tests/foo.bar/README.md new file mode 100644 index 0000000..0ffb829 --- /dev/null +++ b/tests/foo.bar/README.md @@ -0,0 +1,9 @@ + + +# Hello + +Nothing to see. diff --git a/tests/foo.bar/galaxy.yml b/tests/foo.bar/galaxy.yml new file mode 100644 index 0000000..5139974 --- /dev/null +++ b/tests/foo.bar/galaxy.yml @@ -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/ diff --git a/tests/foo.bar/meta/runtime.yml b/tests/foo.bar/meta/runtime.yml new file mode 100644 index 0000000..d642fb8 --- /dev/null +++ b/tests/foo.bar/meta/runtime.yml @@ -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'