summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/sops/.github/workflows/ee.yml
blob: a3d730e7a689b9c47029ca1a68ad22807618f66f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
# 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: execution environment
on:
  # Run CI against all pushes (direct commits, also merged PRs), Pull Requests
  push:
    branches:
      - main
      - stable-*
  pull_request:
  # Run CI once per day (at 05:30 UTC)
  # This ensures that even if there haven't been commits that we are still testing against latest version of ansible-builder
  schedule:
    - cron: '30 5 * * *'

env:
  NAMESPACE: community
  COLLECTION_NAME: sops

jobs:
  build:
    name: Build and test EE (Ⓐ${{ matrix.runner_tag }})
    strategy:
      matrix:
        runner_tag:
          - devel
          - stable-2.12-latest
          - stable-2.11-latest
        execute_playbook:
          - ansible-playbook -v community.sops.install_localhost
        include:
          - runner_tag: stable-2.9-latest
            execute_playbook: ansible localhost -m include_role -a name=community.sops.install -e sops_install_on_localhost=true -e ansible_python_interpreter=/usr/libexec/platform-python
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v3
        with:
          path: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install ansible-builder and ansible-navigator
        run: pip install ansible-builder ansible-navigator

      - name: Verify requirements
        run: ansible-builder introspect --sanitize .

      - name: Make sure galaxy.yml has version entry
        run: >-
          python -c
          'import yaml ;
          f = open("galaxy.yml", "rb") ;
          data = yaml.safe_load(f) ;
          f.close() ;
          data["version"] = data.get("version") or "0.0.1" ;
          f = open("galaxy.yml", "wb") ;
          f.write(yaml.dump(data).encode("utf-8")) ;
          f.close() ;
          '
        working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}

      - name: Build collection
        run: |
          ansible-galaxy collection build --output-path ../../../
        working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}

      - name: Create files for building execution environment
        run: |
          COLLECTION_FILENAME="$(ls "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz)"

          # EE config
          cat > execution-environment.yml <<EOF
          ---
          version: 1
          build_arg_defaults:
            EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:${{ matrix.runner_tag }}'
          dependencies:
            galaxy: requirements.yml
          additional_build_steps:
            append:
              - RUN ${{ matrix.execute_playbook }}
          EOF
          echo "::group::execution-environment.yml"
          cat execution-environment.yml
          echo "::endgroup::"

          # Requirements
          cat > requirements.yml <<EOF
          ---
          collections:
            - name: ${COLLECTION_FILENAME}
              type: file
          EOF
          echo "::group::requirements.yml"
          cat requirements.yml
          echo "::endgroup::"

      - name: Build image based on ${{ matrix.runner_tag }}
        run: |
          mkdir -p context/_build/
          cp "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz context/_build/
          ansible-builder build -v 3 -t test-ee:latest --container-runtime=podman

      - name: Run basic tests
        run: >
          ansible-navigator run
          --mode stdout
          --pull-policy never
          --set-environment-variable ANSIBLE_PRIVATE_ROLE_VARS=true
          --execution-environment-image test-ee:latest
          -v
          all.yml
        working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}/tests/ee