-
-
Notifications
You must be signed in to change notification settings - Fork 102
166 lines (144 loc) · 5.69 KB
/
sandbox.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
name: CI
on:
push:
paths-ignore:
- '.github/**'
- '*.md'
- '.gitignore'
- 'roles/settings/**'
pull_request:
paths-ignore:
- '*.md'
- '.gitignore'
- 'roles/settings/**'
workflow_dispatch:
jobs:
ansible-lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install packages
run: pip install "ansible>=9.0.0,<10.0.0" ansible-lint==6.22.2 jmespath
- name: Run ansible linter
run: ansible-lint
- name: Run salty linter
run: python3 ./scripts/salty-linter.py ./roles
check-entries:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Check Missing Entries
run: ./scripts/check_missing_entries.sh
add-contributors:
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- uses: BobAnkh/add-contributors@master
with:
REPO_NAME: 'saltyorg/Sandbox'
CONTRIBUTOR: '### Contributors'
COLUMN_PER_ROW: '6'
ACCESS_TOKEN: ${{ secrets.GH_TOKEN }}
IMG_WIDTH: '100'
FONT_SIZE: '14'
PATH: '/README.md'
COMMIT_MESSAGE: 'docs(README): update contributors'
AVATAR_SHAPE: 'square'
find-roles:
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: echo "matrix={\"roles\":[$(awk '/# Apps Start/{flag=1;next}/# Apps End/{flag=0}flag' sandbox.yml | awk '!/#/' | awk -F'[][]' '{print $2}' | tr '\n' ',' | sed 's/,*$//' | awk -F',' '{ for( i=1; i<=NF; i++ ) print $i }' | awk '{ gsub(/ /,""); print }'| sort -u | awk -vORS=, '{ print $1 }' | sed 's/,$/\n/')]}" >> $GITHUB_OUTPUT
install:
name: '${{ matrix.roles }}'
needs: [ansible-lint, check-entries, find-roles]
runs-on: ubuntu-22.04
strategy:
matrix: ${{ fromJson(needs.find-roles.outputs.matrix) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
shell: bash
command: curl https://raw.githubusercontent.com/saltyorg/sb/master/sb_install.sh --output sb_install.sh && sudo bash sb_install.sh -v && ansible --version
- name: Chown /srv/git
run: sudo chown -R runner:runner /srv/git
- name: Edit accounts.yml
run: cd /srv/git/saltbox && sed -i 's/seed/runner/g' accounts.yml
- name: Create, chown and chmod /tmp/ansible
run: sudo mkdir /tmp/ansible && sudo chown -R runner:runner /tmp/ansible && chmod 0777 /tmp/ansible
- name: Syntax Check
run: cd /srv/git/saltbox && sudo ansible-playbook saltbox.yml --syntax-check
- name: Install Saltbox Core
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
shell: bash
command: cd /srv/git/saltbox && sudo ansible-playbook saltbox.yml --tags "core" --skip-tags "settings" --extra-vars '{"continuous_integration":true}'
- name: Copy default configuration
run: cp -n defaults/ansible.cfg.default ansible.cfg && cp -n defaults/settings.yml.default settings.yml
- name: Install ${{ matrix.roles }}
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
shell: bash
command: sudo ansible-playbook sandbox.yml --tags "${{ matrix.roles }}" --skip-tags "settings" --extra-vars '{"continuous_integration":true}'
webhook:
name: 'webhook'
runs-on: self-hosted
needs: install
if: always() && github.event_name != 'pull_request' && github.event.repository.fork == false
steps:
- name: Determine Workflow Conclusion
run: |
max_attempts=5
attempt=0
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt + 1))
echo "Attempt $attempt of $max_attempts"
response=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs")
if [ "$?" -eq 0 ]; then
echo "API Request successful."
break
else
echo "API Request failed, retrying in $((attempt * 2)) seconds..."
sleep $((attempt * 2))
fi
done
if [ $attempt -eq $max_attempts ]; then
echo "API requests failed after $max_attempts attempts, defaulting to failure."
echo "WORKFLOW_CONCLUSION=failure" >> $GITHUB_ENV
else
conclusions=$(echo "$response" | jq '[.jobs[].conclusion] | unique | .[]')
if echo "$conclusions" | grep -q "cancelled"; then
echo "Some jobs were cancelled."
echo "WORKFLOW_CONCLUSION=cancelled" >> $GITHUB_ENV
elif echo "$conclusions" | grep -q "failure"; then
echo "Some jobs failed."
echo "WORKFLOW_CONCLUSION=failure" >> $GITHUB_ENV
elif echo "$conclusions" | grep -q "success"; then
echo "All jobs succeeded or were skipped."
echo "WORKFLOW_CONCLUSION=success" >> $GITHUB_ENV
else
echo "Defaulting to failure due to uncertain job conclusions."
echo "WORKFLOW_CONCLUSION=failure" >> $GITHUB_ENV
fi
fi
- uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
status: ${{ env.WORKFLOW_CONCLUSION }}