From 95233f049e0b0d1e2b5bbc8c5c0527d53f7b82f8 Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Mon, 30 Dec 2024 09:59:01 +0100 Subject: [PATCH] manually update github actions from current moduleysnc template --- .github/workflows/ci.yml | 132 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b29b925a5..eef82f6dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,93 @@ --- name: CI -on: pull_request +on: + workflow_call: + inputs: + pidfile_workaround: + description: How to apply the systemd PIDFile workaround for acceptance tests, if at all + default: 'false' + required: false + type: string + rubocop: + description: Whether to run Rubocop + default: true + required: false + type: boolean + timeout_minutes: + description: The maximum time (in minutes) for a job to take. + default: 45 + required: false + type: number + working-directory: + description: The working directory where all jobs should be executed. Used for modules in subdirectories like a monorepo or a control repository. + default: '.' + required: false + type: string + cache-version: + description: The cache version to pass to setup-ruby + default: '0' + required: false + type: string + additional_packages: + description: String of additional packages that should be installed + default: '' + required: false + type: string + beaker_hypervisor: + description: The hypervisor beaker will use to start containers/VMs + default: docker + required: false + type: string + install_vagrant_dependencies: + description: When true and beaker_hypervisor==vagrant_libvirt, we will install vagrant + libvirt + default: true + required: false + type: boolean + beaker_facter: + description: Expand the Beaker matrix based on a fact + default: 'false' + required: false + type: string + beaker_hosts: + description: Expand the Beaker setfile with hosts and roles + default: 'false' + required: false + type: string + domain: + description: The domain that will be used for the beaker instances + default: "example.com" + required: false + type: string + unit_runs_on: + description: the runner group used for unit jobs run on + default: ubuntu-24.04 + required: false + type: string + acceptance_runs_on: + description: the runner group used for acceptance jobs run on + default: ubuntu-24.04 + required: false + type: string + secrets: + beaker_hcloud_token: + description: token to access the Hetzner Cloud API + required: false +env: + BEAKER_HYPERVISOR: ${{ inputs.beaker_hypervisor }} concurrency: group: ${{ github.ref_name }} cancel-in-progress: true jobs: setup_matrix: - name: 'Setup Test Matrix' - runs-on: ubuntu-latest - timeout-minutes: 40 + defaults: + run: + working-directory: ${{ inputs.working-directory }} + name: Static validations + runs-on: ubuntu-24.04 + timeout-minutes: ${{ inputs.timeout_minutes }} outputs: puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} puppet_beaker_test_matrix: ${{ steps.get-outputs.outputs.puppet_beaker_test_matrix }} @@ -20,18 +96,26 @@ jobs: PUPPET_GEM_VERSION: ">= 7.0" steps: - uses: actions/checkout@v4 + - name: install additional packages + if: ${{ inputs.additional_packages != '' }} + run: | + sudo apt-get update + sudo apt-get install -y ${{ inputs.additional_packages }} - name: Setup ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' + ruby-version: '3.2' bundler-cache: true + cache-version: ${{ inputs.cache-version }} + working-directory: ${{ inputs.working-directory }} - name: Run static validations run: bundle exec rake validate lint check - name: Run rake rubocop run: bundle exec rake rubocop + if: ${{ inputs.rubocop }} - name: Setup Test Matrix id: get-outputs - run: bundle exec metadata2gha --pidfile-workaround false --domain example.com + run: bundle exec metadata2gha --domain ${{ inputs.domain }} --pidfile-workaround ${{ inputs.pidfile_workaround }} --beaker-facter "${{ inputs.beaker_facter }}" --beaker-hosts "${{ inputs.beaker_hosts }}" unit: needs: setup_matrix @@ -56,10 +140,14 @@ jobs: run: bundle exec rake parallel_spec acceptance: + defaults: + run: + working-directory: ${{ inputs.working-directory }} needs: setup_matrix - runs-on: ubuntu-20.04 + runs-on: ${{ inputs.acceptance_runs_on }} env: BUNDLE_WITHOUT: development:test:release + BEAKER_HCLOUD_TOKEN: '${{ secrets.beaker_hcloud_token }}' strategy: fail-fast: false matrix: @@ -67,11 +155,31 @@ jobs: name: "${{ matrix.name }}" steps: - uses: actions/checkout@v4 + - name: install additional packages + if: ${{ inputs.additional_packages != '' }} + run: | + sudo apt-get update + sudo apt-get install -y ${{ inputs.additional_packages }} + - name: Setup podman + if: ${{ inputs.beaker_hypervisor == 'container_podman' }} + run: | + systemctl start --user podman.socket + echo "DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock" >> "$GITHUB_ENV" + - name: Setup libvirt for Vagrant + if: ${{ inputs.beaker_hypervisor == 'vagrant_libvirt' && inputs.install_vagrant_dependencies == true }} + run: | + sudo add-apt-repository ppa:evgeni/vagrant + sudo apt-get update + sudo apt-get install -y --no-install-recommends vagrant vagrant-libvirt libvirt-daemon-system libvirt-daemon qemu-system-x86 qemu-utils dnsmasq + sudo chmod 666 /var/run/libvirt/libvirt-sock - name: Setup ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' + ruby-version: '3.2' bundler-cache: true + cache-version: ${{ inputs.cache-version }} + working-directory: ${{ inputs.working-directory }} + self-hosted: ${{ ! startsWith(inputs.acceptance_runs_on, 'ubuntu-') }} - name: Start squid run: ./scripts/start-squid.sh - name: Run tests @@ -82,10 +190,14 @@ jobs: if: always() tests: + if: always() needs: - unit - acceptance - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 name: Test suite steps: - - run: echo Test suite completed + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }}