-
Notifications
You must be signed in to change notification settings - Fork 42
141 lines (124 loc) · 4.88 KB
/
push-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
name: Prod EE Build
on:
push:
branches:
- main
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:
fetch-depth: 0
- name: Generate matrix
id: generate-matrix
working-directory: ${{ github.workspace }}
run: |
python -u .github/workflows/generate_matrix.py \
--start-ref $(git rev-parse HEAD^1) \
--end-ref $(git rev-parse HEAD) \
--output matrix_output.json
- name: Read matrix
id: set-matrix
working-directory: ${{ github.workspace }}
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"
build-ee:
needs: [prepare-matrix]
if: ${{ needs.prepare-matrix.outputs.length != '0' }}
runs-on: ubuntu-latest
environment: deploy
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
fail-fast: false
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Fetch the base and head refs
run: |
git fetch origin ${{ github.base_ref }}
git fetch origin ${{ github.head_ref }}
- name: Install python requirements (ansible-builder)
run: pip install -r requirements.txt
- name: Define environment variables
run: |
echo "EE=${{ matrix.ee }}" >> $GITHUB_ENV
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
- name: Log in to quay.io
uses: redhat-actions/podman-login@v1
with:
registry: quay.io
username: ${{ secrets.REDHAT_USERNAME }}
password: ${{ secrets.REDHAT_PASSWORD }}
- name: Log in to registry.redhat.io
uses: redhat-actions/podman-login@v1
with:
registry: registry.redhat.io
username: ${{ secrets.REDHAT_USERNAME }}
password: ${{ secrets.REDHAT_PASSWORD }}
- name: Substitute token for automation hub
run: |
sed -i "s/my_ah_token/${{ secrets.AH_TOKEN }}/1" ansible.cfg
- name: (devel) Build image and create artifact
run: |
echo "Would build: ${{ env.EE }}"
- 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 "EE: ${{ env.EE }}" >> $COMMANDS_FILE
echo "" >> $COMMANDS_FILE
echo "\`\`\`" > $COMMANDS_FILE
echo "podman pull quay.io/${{ secrets.QUAY_USER }}/${{ 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 quay.io
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.EE }}
tags: ${{ env.IMAGE_TAG }} ${{ github.sha }}
registry: quay.io/${{ secrets.QUAY_USER }}/
username: ${{ secrets.REDHAT_USERNAME }}
password: ${{ secrets.REDHAT_PASSWORD }}
- name: Print summary
run: |
echo "## :rocket: Usage" >> $GITHUB_STEP_SUMMARY
echo "Image pushed to repository: quay.io/${{ secrets.QUAY_USER }}/${{ env.EE }}:${{ env.IMAGE_TAG }}" >> $GITHUB_STEP_SUMMARY
echo "> \`podman pull quay.io/${{ secrets.QUAY_USER }}/${{ env.EE }}:${{ env.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY