Skip to content

Update execution-environment.yml #306

Update execution-environment.yml

Update execution-environment.yml #306

Workflow file for this run

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()
});