Skip to content

Commit

Permalink
Refactor release CI (#12)
Browse files Browse the repository at this point in the history
* Refactor release CI

Image tags will be generated based upon the event that triggered the workflow:
  - push event:
    - main branch: latest
    - devel branch: devel
    - all other branches: <branch name>-latest
      Branches must be added to the on.push.branches array above to trigger
  - pull_request event: DEV-PR-<pull_request_number>
    Branches must be added to the on.pull_request.branches array above to trigger
  - release event: <tag_name>
  - schedule event: nightly
    This will be the same configuration as the 'latest' tag, but may contain updated packages, etc. from upstream
  - all other events: <first 7 chars of commit sha>

Run podman test as part of same workflow as release (fail faster)

* Build on PR to feature branch

* Update PR CI

No need to run on changes of only markdown files
  • Loading branch information
syndr authored Dec 2, 2024
1 parent 37bcd2f commit 104ed5f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 131 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/build-devel-latest.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/build-latest.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/ci.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/merge-pr.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---

name: "Create Tag on Pull Request merge"
on:
pull_request:
types:
- closed
branches:
- main
paths:
- "./**"
- '!**/*.md'

jobs:
TagMerge:
Expand Down Expand Up @@ -73,3 +78,4 @@ jobs:
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
"${{ github.event.pull_request._links.comments.href }}" \
-d '{"body":"Created tag v${{ steps.tagged.outputs.newtag }}"}'
104 changes: 99 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,85 @@
name: Release
---
# This workflow will build and push an AWX EE image to a container registry based upon the provided configuration
#
# Image tags will be generated based upon the event that triggered the workflow:
# - push event:
# - main branch: latest
# - devel branch: devel
# - all other branches: <branch name>-latest
# Branches must be added to the on.push.branches array above to trigger
# - pull_request event: DEV-PR-<pull_request_number>
# Branches must be added to the on.pull_request.branches array above to trigger
# - release event: <tag_name>
# - schedule event: nightly
# This will be the same configuration as the 'latest' tag, but may contain updated packages, etc. from upstream
# - all other events: <first 7 chars of commit sha>
#
# Variables:
# IMAGE_REGISTRY_URL: The container registry to push the image to (default: ghcr.io)
# IMAGE_REPOSITORY: The repository to push the image to (default: github.repository)
# IMAGE_REGISTRY_USER: The username to authenticate with the container registry (default: github.actor)
#
# Secrets:
# IMAGE_REGISTRY_TOKEN: The token to authenticate with the container registry (default: secrets.GITHUB_TOKEN)
#

name: Build & Release

on:
push:
# build and push anytime commits are merged to specified branches
branches:
- main
- devel
paths:
- ".github/workflows/release.yml"
- "./**"
- '!**/*.md'
pull_request:
# build and push anytime a pull request is opened or synchronized
branches:
- main
- devel
- build-runner # Remove this line before merging to 'main' or 'devel'
paths:
- ".github/workflows/release.yml"
- "./**"
- '!**/*.md'
release:
# build and push anytime a release is created
types:
- created
schedule:
# build and push nightly
- cron: "13 4 * * *"

jobs:
ci:
runs-on: ubuntu-latest
name: CI Build (Podman)
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install -r requirements.txt
- name: Build EE with Podman
run: |
ansible-builder build -v3 -t ${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}/${{ vars.IMAGE_REPOSITORY || github.repository }} --container-runtime=podman
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
name: Release
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v4

Expand All @@ -21,9 +92,32 @@ jobs:
python -m pip install --upgrade pip setuptools
pip install -r requirements.txt
- name: Quay login
- name: Login to Docker Container Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}
username: ${{ vars.IMAGE_REGISTRY_USER || github.actor }}
password: ${{ secrets.IMAGE_REGISTRY_TOKEN || secrets.GITHUB_TOKEN }}

- name: Generate image tag
run: |
echo "${{ secrets.QUAY_TOKEN }}" | docker login quay.io -u ${{ secrets.QUAY_USERNAME }} --password-stdin
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "devel" ]]; then
echo "IMAGE_TAG=devel" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.ref_name }}-latest" >> $GITHUB_ENV
fi
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "IMAGE_TAG=DEV-PR-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "release" ]]; then
echo "IMAGE_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "IMAGE_TAG=nightly" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_ENV
fi
- name: Build and push image
run: |
Expand All @@ -33,6 +127,6 @@ jobs:
docker buildx build \
--push \
--platform=linux/amd64,linux/arm64 \
--tag=${{ vars.IMAGE_REGISTRY }}:${{ github.event.release.tag_name }} \
--tag=${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}/${{ vars.IMAGE_REPOSITORY || github.repository }}:${{ env.IMAGE_TAG }} \
context

0 comments on commit 104ed5f

Please sign in to comment.