Merge pull request #152 from HichamMourad/main #109
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |