Run CI when a draft PR is marked ready for review #1451
Workflow file for this run
This file contains hidden or 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: Test Collection Roles | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| logLevel: | |
| description: 'Log level' | |
| required: true | |
| default: 'warning' | |
| type: choice | |
| options: | |
| - info | |
| - warning | |
| - debug | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| paths: | |
| - 'roles/**' | |
| - '!roles/**/*.md' | |
| - '!roles/**/meta/argument_specs.yml' | |
| - 'molecule/elasticstack_default/**' | |
| - 'requirements-test.txt' | |
| - '.github/workflows/test_roles_pr.yml' | |
| - 'galaxy.yml' # When changing dependencies parameter | |
| # Cancel outdated pipeline runs when a new push occurs in the pull request and a new pipeline starts. | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint_collection: | |
| # For non-PR events (workflow_dispatch, merge_group, schedule, push, etc.), github.event.pull_request.draft is null. | |
| # GitHub Actions coerces null == false to true (null → 0, false → 0), so the job runs for all non-draft events. | |
| if: github.event.pull_request.draft == false | |
| uses: ./.github/workflows/test_linting.yml | |
| with: | |
| rolename: '' | |
| molecule_core_2_19: | |
| runs-on: ubuntu-latest | |
| needs: lint_collection | |
| env: | |
| COLLECTION_NAMESPACE: netways | |
| COLLECTION_NAME: elasticstack | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| distro: | |
| - rockylinux9 | |
| - ubuntu2204 | |
| scenario: | |
| - elasticstack_default | |
| release: | |
| - 8 | |
| python_version: | |
| - "3.11" | |
| ansible_version: | |
| - "ansible-core>=2.19,<2.20" #Correspond ansible>=12.0,<13.0 | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v7 | |
| - name: Set up Python ${{ matrix.python_version }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python_version }} | |
| cache: 'pip' | |
| cache-dependency-path: requirements-test.txt | |
| - name: Install dependencies | |
| run: | | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install "${{ matrix.ansible_version }}" | |
| python3 -m pip install -r requirements-test.txt | |
| - name: Get latest Elasticsearch release | |
| id: elastic-version | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| run: | | |
| curl -fsSL \ | |
| "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ | |
| -o /tmp/Packages.gz | |
| VERSION=$(zcat /tmp/Packages.gz \ | |
| | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ | |
| | sort -V \ | |
| | tail -n 1) | |
| rm -f /tmp/Packages.gz | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Debug - latest Elasticsearch version | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" | |
| - name: Restore Elastic apt cache | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| uses: actions/cache/restore@v6 | |
| with: | |
| path: /tmp/elastic-apt-cache | |
| key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} | |
| restore-keys: | | |
| ${{ runner.os }}-apt-elastic-${{ matrix.release }}. | |
| - name: Debug - apt cache contents | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| run: | | |
| echo "=== /tmp/elastic-apt-cache/ ===" | |
| ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" | |
| echo "=== Total size ===" | |
| du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" | |
| - name: Ensure apt cache directory exists | |
| run: mkdir -p /tmp/elastic-apt-cache | |
| - name: Install collection | |
| run: | | |
| mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE | |
| cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME | |
| - name: Test with molecule | |
| run: | | |
| ansible --version | |
| molecule --version | |
| molecule test -s ${{ matrix.scenario }} | |
| env: | |
| MOLECULE_DISTRO: ${{ matrix.distro }} | |
| PY_COLORS: '1' | |
| ANSIBLE_FORCE_COLOR: '1' | |
| ELASTIC_RELEASE: ${{ matrix.release }} | |
| molecule_core_2_20: | |
| runs-on: ubuntu-latest | |
| needs: lint_collection | |
| env: | |
| COLLECTION_NAMESPACE: netways | |
| COLLECTION_NAME: elasticstack | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| distro: | |
| - rockylinux9 | |
| - ubuntu2204 | |
| scenario: | |
| - elasticstack_default | |
| release: | |
| - 8 | |
| python_version: | |
| - "3.14" | |
| ansible_version: | |
| - "ansible-core>=2.20,<2.21" #Correspond ansible>=13.0,<14.0 | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v7 | |
| - name: Set up Python ${{ matrix.python_version }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python_version }} | |
| cache: 'pip' | |
| cache-dependency-path: requirements-test.txt | |
| - name: Install dependencies | |
| run: | | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install "${{ matrix.ansible_version }}" | |
| python3 -m pip install -r requirements-test.txt | |
| - name: Get latest Elasticsearch release | |
| id: elastic-version | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| run: | | |
| curl -fsSL \ | |
| "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ | |
| -o /tmp/Packages.gz | |
| VERSION=$(zcat /tmp/Packages.gz \ | |
| | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ | |
| | sort -V \ | |
| | tail -n 1) | |
| rm -f /tmp/Packages.gz | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Debug - latest Elasticsearch version | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" | |
| - name: Restore Elastic apt cache | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| uses: actions/cache/restore@v6 | |
| with: | |
| path: /tmp/elastic-apt-cache | |
| key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} | |
| restore-keys: | | |
| ${{ runner.os }}-apt-elastic-${{ matrix.release }}. | |
| - name: Debug - apt cache contents | |
| if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') | |
| run: | | |
| echo "=== /tmp/elastic-apt-cache/ ===" | |
| ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" | |
| echo "=== Total size ===" | |
| du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" | |
| - name: Ensure apt cache directory exists | |
| run: mkdir -p /tmp/elastic-apt-cache | |
| - name: Install collection | |
| run: | | |
| mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE | |
| cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME | |
| - name: Test with molecule | |
| run: | | |
| ansible --version | |
| molecule --version | |
| molecule test -s ${{ matrix.scenario }} | |
| env: | |
| MOLECULE_DISTRO: ${{ matrix.distro }} | |
| PY_COLORS: '1' | |
| ANSIBLE_FORCE_COLOR: '1' | |
| ELASTIC_RELEASE: ${{ matrix.release }} |