-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (143 loc) · 4.55 KB
/
main.yml
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Main
on:
push:
branches: [main]
tags:
- "v*"
pull_request:
branches: [main]
permissions:
contents: read
env:
ANSIBLE_COLLECTIONS_PATH: ~/.ansible/collections
ANSIBLE_HOME: ~/.ansible
MOLECULE_PARALLEL: "1"
PY_COLORS: "1"
jobs:
lint-py:
name: Lint Python code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
with:
cache: poetry
- name: Install deps
run: poetry install
- name: Lint code
run: poetry run poe lint
lint:
name: Lint Ansible code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache ansible requirements
id: cache-reqs
uses: actions/cache@v4
with:
key: reqs-${{ runner.os }}-${{ hashFiles('requirements.yml') }}
path: ${{ env.ANSIBLE_COLLECTIONS_PATH }}
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
with:
cache: poetry
- name: Install deps
run: poetry install --no-root
- name: Install requirements
if: steps.cache-reqs.outputs.cache-hit != 'true'
run: poetry run ansible-galaxy install -r requirements.yml
- name: Lint code
run: poetry run ansible-lint
# TODO: try https://github.com/tj-actions/changed-files
changes:
name: Detect changed scenarios
permissions:
pull-requests: read
runs-on: ubuntu-latest
outputs:
# If no changes detected, return hello_world scenario
discover: ${{ steps.filter.outputs.changes != '[]' && steps.filter.outputs.changes || '["plugins/tests/molecule/hello_world"]' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for file changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: .github/file-filters.yml
tests:
name: Tests
needs: [changes]
strategy:
fail-fast: false
matrix:
molecule-distro: [debian12, ubuntu2204]
molecule-discover: ${{ fromJSON(needs.changes.outputs.discover) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache ansible requirements
id: cache-reqs
uses: actions/cache@v4
with:
key: reqs-${{ runner.os }}-${{ hashFiles('requirements.yml') }}
path: ${{ env.ANSIBLE_COLLECTIONS_PATH }}
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
with:
cache: poetry
- name: Install deps
run: poetry install --no-root
- name: Install requirements
if: steps.cache-reqs.outputs.cache-hit != 'true'
run: poetry run ansible-galaxy install -r requirements.yml
- name: Run tests
# FIXME: shared is not a valid scenario
if: matrix.molecule-discover != 'shared'
run: poetry run poe test --discover ${{ matrix.molecule-discover }}
env:
MOLECULE_DISTRO: ${{ matrix.molecule-distro }}
galaxy-deploy:
name: Release to Ansible Galaxy
if: github.ref_type == 'tag'
needs: [lint-py, lint, tests]
environment:
name: galaxy
url: https://galaxy.ansible.com/ui/repo/published/deadnews/util
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set version in galaxy.yml
run: |
sed "s|^version:.*$|version: ${GITHUB_REF_NAME#v}|" -i galaxy.yml
- name: Upload collection to Ansible Galaxy
uses: ansible/ansible-publish-action@v1.0.0
with:
api_key: ${{ secrets.GALAXY_API_KEY }}
github-deploy:
name: Release to GitHub
if: github.ref_type == 'tag'
needs: [lint-py, lint, tests]
environment: github-releases
permissions:
contents: write
env:
CHANGELOG: https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md
PRERELEASE: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
run: |
gh release create ${{ github.ref_name }} \
--title ${{ github.ref_name }} \
--notes="See [the CHANGELOG](${{ env.CHANGELOG }}) for more details." \
--draft=${{ env.PRERELEASE }} \
--prerelease=${{ env.PRERELEASE }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}