-
Notifications
You must be signed in to change notification settings - Fork 42
213 lines (185 loc) · 7.25 KB
/
pr-ee-build.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Devel EE Build
on:
pull_request_target:
branches:
- main
types: [opened, reopened, synchronize]
jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
length: ${{ steps.set-matrix.outputs.length }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref != '' && github.event.pull_request.head.ref || 'main' }}
- name: Generate matrix
id: generate-matrix
run: |
echo $GITHUB_BASE_REF
echo $GITHUB_HEAD_REF
python -u .github/workflows/generate_matrix.py \
--start-ref origin/$GITHUB_BASE_REF \
--end-ref $GITHUB_HEAD_REF \
--output-path matrix_output.json
- name: Read matrix
id: set-matrix
run: |
MATRIX_JSON=$(cat matrix_output.json)
echo "::set-output name=matrix::$MATRIX_JSON"
MATRIX_LENGTH=$(echo $MATRIX_JSON | jq '.include | length')
echo $MATRIX_LENGTH
echo "::set-output name=length::$MATRIX_LENGTH"
debug:
needs: [prepare-matrix]
if: ${{ needs.prepare-matrix.outputs.length != '0' }}
runs-on: ubuntu-latest
environment: test
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
fail-fast: false
steps:
- name: Print working directory
run: pwd
- name: List files in the directory
run: ls -lah
- name: List environment variables
run: printenv
- name: Show git branch and commit
run: |
echo "Current Branch:"
git branch
echo "Current Commit:"
git rev-parse HEAD
- name: Fetch all branches
run: git fetch --all
- name: List all remote branches
run: git branch -r
- name: Show detailed git diff
run: git diff origin/main
build-ee:
needs: [prepare-matrix]
if: ${{ needs.prepare-matrix.outputs.length != '0' }}
outputs:
push_success: ${{ steps.push_to_ghcr.outputs.push_success }}
runs-on: ubuntu-latest
environment: test
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
fail-fast: false
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install python requirements (ansible-builder)
run: pip install -r requirements.txt
- name: Define environment variables
run: |
echo "EE=${{ matrix.ee }}" >> $GITHUB_ENV
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "IMAGE_TAG=pr-${{ github.event.number }}-$SHORT_SHA" >> $GITHUB_ENV
echo "IMAGE_REGISTRY=ghcr.io" >> $GITHUB_ENV
- name: Login to ghcr
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to registry.redhat.io
uses: redhat-actions/podman-login@v1
with:
registry: registry.redhat.io
username: ${{ secrets.REDHAT_SA_USERNAME }}
password: ${{ secrets.REDHAT_SA_PASSWORD }}
- name: Substitute token for automation hub
run: |
sed -i "s/my_ah_token/${{ secrets.AH_TOKEN }}/1" ansible.cfg
- name: Build image and create artifact
working-directory: ${{ matrix.ee }}
run: |
ansible-builder build -v 3 \
--build-arg AH_TOKEN=${{ secrets.AH_TOKEN }} \
--context=../${{ env.EE }} \
--tag=${{ env.EE }}:${{ env.IMAGE_TAG }} \
--tag=${{ env.EE }}:${{ github.sha }}
# Create artifact file
COMMANDS_FILE="commands-${{ matrix.ee }}.txt"
echo "" >> $COMMANDS_FILE
echo "${{ env.EE }}" >> $COMMANDS_FILE
echo "" >> $COMMANDS_FILE
echo "\`\`\`" > $COMMANDS_FILE
echo "podman pull ${{ env.IMAGE_REGISTRY }}/${{ github.repository_owner }}/${{ env.EE }}:${{ env.IMAGE_TAG }}" >> $COMMANDS_FILE
echo "\`\`\`" >> $COMMANDS_FILE
echo "<details>" >> $COMMANDS_FILE
echo "<summary><b>More info...</b></summary>" >> $COMMANDS_FILE
echo "" >> $COMMANDS_FILE
echo "#### Installed collections" >> $COMMANDS_FILE
echo "" >> $COMMANDS_FILE
echo "\`\`\`" >> $COMMANDS_FILE
podman run -it ${{ env.EE }}:${{ env.IMAGE_TAG }} ansible-galaxy collection list >> $COMMANDS_FILE
echo "\`\`\`" >> $COMMANDS_FILE
echo "" >> $COMMANDS_FILE
echo "#### Ansible version" >> $COMMANDS_FILE
echo "" >> $COMMANDS_FILE
echo "\`\`\`" >> $COMMANDS_FILE
podman run -it ${{ env.EE }}:${{ env.IMAGE_TAG }} ansible --version >> $COMMANDS_FILE
echo "\`\`\`" >> $COMMANDS_FILE
echo "</details>" >> $COMMANDS_FILE
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: commands-${{ matrix.ee }}
path: ${{ matrix.ee }}/commands-${{ matrix.ee }}.txt
- name: Push To GHCR
id: push_to_ghcr
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.EE }}
tags: ${{ env.IMAGE_TAG }}
registry: ${{ env.IMAGE_REGISTRY }}/${{ github.repository_owner }}
- name: Set push success flag
if: success()
run: echo "push_success=true" >> $GITHUB_ENV
- name: Print summary
run: |
echo "## :rocket: Usage" >> $GITHUB_STEP_SUMMARY
echo "Image pushed to repository: ${{ env.IMAGE_REGISTRY }}/${{ github.repository_owner }}/${{ env.EE }}:${{ env.IMAGE_TAG }}" >> $GITHUB_STEP_SUMMARY
echo "> \`podman pull ${{ env.IMAGE_REGISTRY }}/${{ github.repository_owner }}/${{ env.EE }}:${{ env.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
post-comment:
needs: build-ee
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
- name: Post Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
let commentBody = '### :rocket: **EE Images Built** :rocket:\n\n';
const artifactsDirectory = './'; // Base directory where artifacts are downloaded
fs.readdirSync(artifactsDirectory, { withFileTypes: true }).forEach(dirent => {
if (dirent.isDirectory() && dirent.name.startsWith('commands-')) {
const artifactDirPath = path.join(artifactsDirectory, dirent.name);
fs.readdirSync(artifactDirPath).forEach(file => {
const filePath = path.join(artifactDirPath, file);
const content = fs.readFileSync(filePath, 'utf8');
commentBody += content + '\n';
});
}
});
const prNumber = context.issue.number;
const repo = context.repo;
github.rest.issues.createComment({
...repo,
issue_number: prNumber,
body: commentBody.trim()
});