Skip to content

Release - Automated #20

Release - Automated

Release - Automated #20

Workflow file for this run

---
name: Release - Automated
on:
schedule:
- cron: "0 0 1,15 * *"
workflow_dispatch:
env:
COLLECTION_NAMESPACE: infra
COLLECTION_NAME: controller_configuration
COLLECTION_REPO: https://github.com/redhat-cop/infra.controller_configuration/
jobs:
calculate_version:
name: Calculate Collection Version
runs-on: ubuntu-latest
outputs:
collection_version: ${{ steps.bump-semver.outputs.new_version }}
change_level: ${{ steps.bump_level.outputs.level }}
change_present: ${{ steps.bump_level.outputs.change_present }}
steps:
- uses: actions/checkout@v6
- name: Get the most recent tag
uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
with:
semver_only: true
- name: Calculate bump level
id: bump_level
shell: bash
run: |
if [ -z "$(ls changelogs/fragments/*.yml changelogs/fragments/*.yaml 2>/dev/null)" ]; then
echo "change_present=false" >> "$GITHUB_OUTPUT"
else
echo "change_present=true" >> "$GITHUB_OUTPUT"
fi
MAJOR=1
if grep -RE '(major_changes|breaking_changes)' changelogs/fragments 2>/dev/null; then
MAJOR=0
fi
MINOR=1
if grep -R minor_changes changelogs/fragments 2>/dev/null; then
MINOR=0
fi
if [ $MAJOR -eq 0 ]; then
echo "level=major" >> "$GITHUB_OUTPUT"
echo "Determined change level: major"
elif [ $MINOR -eq 0 ]; then
echo "level=minor" >> "$GITHUB_OUTPUT"
echo "Determined change level: minor"
else
echo "level=patch" >> "$GITHUB_OUTPUT"
echo "Determined change level: patch"
fi
- name: Bump version
uses: actions-ecosystem/action-bump-semver@v1
id: bump-semver
with:
current_version: ${{ steps.get-latest-tag.outputs.tag }}
level: ${{ steps.bump_level.outputs.level }}
changelog:
name: Generate Changelog
needs: calculate_version
if: >-
(needs.calculate_version.outputs.change_level != 'major'
&& needs.calculate_version.outputs.change_present != 'false')
|| github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
token: "${{ secrets.GH_WORKFLOW_KEY }}"
- name: Create release branch
run: |
BRANCH="release/${{ needs.calculate_version.outputs.collection_version }}"
git checkout -B "${BRANCH}"
- uses: actions/setup-python@v6
with:
python-version: "3.x"
- name: Install dependencies
run: pip install --upgrade "ansible-core>=2.15,<2.19" antsibull-changelog
- name: Update galaxy.yml version for changelog
run: |
sed -i "s/^version:.*/version: ${{ needs.calculate_version.outputs.collection_version }}-devel/" galaxy.yml
- name: Generate changelog
run: antsibull-changelog release --verbose --version ${{ needs.calculate_version.outputs.collection_version }}
- name: Push to release branch
uses: devops-infra/action-commit-push@master
with:
github_token: "${{ secrets.GH_WORKFLOW_KEY }}"
add_timestamp: false
commit_prefix: "[AUTO]"
commit_message: "Update changelog ${{ needs.calculate_version.outputs.collection_version }}"
force: false
target_branch: release/${{ needs.calculate_version.outputs.collection_version }}
create_github_release:
name: Create GitHub Release
needs:
- changelog
- calculate_version
runs-on: ubuntu-latest
steps:
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ needs.calculate_version.outputs.collection_version }}
generate_release_notes: true
release_galaxy:
name: Publish to Galaxy
needs:
- create_github_release
- calculate_version
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v6
with:
ref: release/${{ needs.calculate_version.outputs.collection_version }}
- name: Build the collection
run: ansible-galaxy collection build -v --force
- name: Publish the collection on Galaxy
run: |
TARBALL=$(ls -1 ./*.tar.gz)
ansible-galaxy collection publish "${TARBALL}" --api-key "${{ secrets.GALAXY_INFRA_KEY }}"
release_ah:
name: Publish to Automation Hub
needs:
- create_github_release
- calculate_version
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v6
with:
ref: release/${{ needs.calculate_version.outputs.collection_version }}
- name: Set up Ansible
run: pip install --upgrade "ansible-core>=2.16"
- name: Build the collection
run: ansible-galaxy collection build -v --force
- name: Publish to Automation Hub
env:
AH_TOKEN: ${{ secrets.CRC_PUBLISH_KEY }}
run: |
TARBALL=$(ls -1 ./*.tar.gz | head -n1)
cat > ansible.cfg <<EOF
[galaxy]
server_list = rh_automation_hub
[galaxy_server.rh_automation_hub]
url=https://cloud.redhat.com/api/automation-hub/
auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
token=$AH_TOKEN
EOF
ansible-galaxy collection publish "${TARBALL}"
rm -f ansible.cfg
release_check:
name: Verify Releases
needs:
- release_galaxy
- release_ah
runs-on: ubuntu-latest
steps:
- run: echo "All releases completed successfully"
upload_tarball:
name: Upload Tarball to Release
needs:
- create_github_release
- calculate_version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: release/${{ needs.calculate_version.outputs.collection_version }}
- name: Build collection tarball
run: ansible-galaxy collection build -v --force
- name: Upload tarball to GitHub release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GH_WORKFLOW_KEY }}
file: "${{ env.COLLECTION_NAMESPACE }}-${{ env.COLLECTION_NAME }}-*.tar.gz"
file_glob: true
tag: ${{ needs.calculate_version.outputs.collection_version }}
overwrite: true
merge_release:
name: Merge Release Branch
needs:
- calculate_version
- release_check
- upload_tarball
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: release/${{ needs.calculate_version.outputs.collection_version }}
- name: Create and merge release PR
run: |
gh pr create \
--base devel \
--head "release/${{ needs.calculate_version.outputs.collection_version }}" \
--title "[RELEASE] Update changelog ${{ needs.calculate_version.outputs.collection_version }}" \
--body "Updated with changelog for release ${{ needs.calculate_version.outputs.collection_version }}"
gh pr merge "release/${{ needs.calculate_version.outputs.collection_version }}" --rebase --admin
env:
GH_TOKEN: ${{ secrets.GH_WORKFLOW_KEY }}
deploy_ee:
name: Build Execution Environment
needs: merge_release
uses: redhat-cop/ansible_collections_tooling/.github/workflows/build_ee.yml@main
with:
quay_username: redhat_cop
secrets:
quay_token: ${{ secrets.quay_token }}
send_message:
name: Send Matrix Notification
needs:
- release_check
- calculate_version
runs-on: ubuntu-latest
steps:
- name: Send message to newsbot channel
uses: fadenb/matrix-chat-message@v0.0.6
with:
homeserver: "matrix.org"
token: ${{ secrets.matrix_token }}
channel: "!pMZboYFCScZJfXmOtH:ansible.im"
messagetype: "m.text"
message: |
@newsbot ${{ env.COLLECTION_NAMESPACE }}.${{ env.COLLECTION_NAME }} ${{ needs.calculate_version.outputs.collection_version }} has been released.
This Ansible collection allows for easy interaction with an AWX or Ansible Controller server via Ansible roles using the AWX/Controller collection modules.
Visit ${{ env.COLLECTION_REPO }} For more information and updates.
- name: Send message to team channel
uses: fadenb/matrix-chat-message@v0.0.6
with:
homeserver: "matrix.org"
token: ${{ secrets.matrix_token }}
channel: "!ccrdinGkMeyakqWzIM:matrix.org"
messagetype: "m.text"
message: |
${{ env.COLLECTION_NAMESPACE }}.${{ env.COLLECTION_NAME }} ${{ needs.calculate_version.outputs.collection_version }} has been released.
This Ansible collection allows for easy interaction with an AWX or Ansible Controller server via Ansible roles using the AWX/Controller collection modules.
Visit ${{ env.COLLECTION_REPO }} For more information and updates.