Skip to content
50 changes: 38 additions & 12 deletions .github/workflows/sync-extensions.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Sync and Release Extensions

on:
release:
types: [released]
pull_request:
types: [closed]
push:
branches:
- main
Expand All @@ -16,10 +16,15 @@ env:

jobs:
sync:
if: github.repository_owner == 'rancher' && github.ref_type != 'tag'
if: github.event.pull_request.merged != true
name: Sync and Release Extensions
runs-on: ubuntu-latest
permissions: write-all
permissions:
actions: write
contents: write
deployments: write
pages: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -52,6 +57,8 @@ jobs:
git push origin sync-${{ env.NOW }}

- name: Create Pull Request
env:
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
run: |
# Create the PR using the GitHub CLI
pr_number=$(gh pr create \
Expand All @@ -70,11 +77,6 @@ jobs:

# Store the PR number as an output
echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV

- name: Merge Pull Request when approved
run: |
# Merge the PR using the GitHub CLI
gh pr merge ${{ env.PR_NUMBER }} --delete-branch --merge --repo ${{ github.repository }}

- name: Run chart-releaser
uses: helm/[email protected]
Expand All @@ -84,31 +86,55 @@ jobs:
CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
CR_SKIP_EXISTING: true
sync-catalogs:
if: github.repository_owner == 'rancher' && github.ref_type == 'tag'
if: github.event.pull_request.merged == true
name: Sync and Release Extension Catalog
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
contents: write
packages: write

steps:
- name: Check PR title
id: check_title
run: |
title="${{ github.event.pull_request.title }}"
if [[ "$title" == *"Create PR for extension sync"* ]]; then
echo "match=true" >> $GITHUB_OUTPUT
else
echo "match=false" >> $GITHUB_OUTPUT
fi

- name: Checkout repository
if: steps.check_title.outputs.match == 'true'
uses: actions/checkout@v4

- name: Configure Git
if: steps.check_title.outputs.match == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'

- name: Login to Container Registry
if: steps.check_title.outputs.match == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Sync Catalog Image with Registry
if: steps.check_title.outputs.match == 'true'
id: sync_catalog_script
run: |
chmod +x ./scripts/bundle-catalog
./scripts/bundle-catalog -t ${{ github.ref_name }}
./scripts/bundle-catalog

- name: Create Release tag in repo
if: steps.check_title.outputs.match == 'true'
id: create-release-tag
run: |
gh release create ${{ steps.sync_catalog_script.outputs.GH_RELEASE_TAG }} \
--title "Release extensions catalog ${{ steps.sync_catalog_script.outputs.GH_RELEASE_TAG }}" \
--notes "Automated release from workflow: \n\n\n\n $(jq . manifest.json | less)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 35 additions & 1 deletion scripts/bundle-catalog
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BOLD="\033[1m"
NORMAL="\033[22m"
CHECK="\xE2\x9C\x94"

DOCKERHUB_REPO="rancher/ui-plugin-catalog"
DEST_IMAGE_NAME="ui-plugin-catalog"
DEST_TAG="latest"
DEST_REGISTRY=""
Expand Down Expand Up @@ -171,6 +172,39 @@ do
rm -rf ./tmp/${NAME}
done

# if no tag is passed, get the latest version from dockerhub and bump the minor version
if [[ "${DEST_TAG}" == "latest" ]]; then
echo "No tag argument passed. Fetching tags for Docker Hub repo: $DOCKERHUB_REPO"

# Get latest semver tag
TAGS=$(curl -s "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/tags/?page_size=100" | jq -r '.results[].name')

LATEST_TAG=$(echo "$TAGS" \
| grep -v '^latest$' \
| grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' \
| sort -Vr \
| head -n 1)

if [[ -z "$LATEST_TAG" ]]; then
echo "No semantic version tags found."
exit 1
fi

echo "Latest tag: $LATEST_TAG"

# Extract version parts
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG"

# Calculate next minor version
NEXT_MINOR=$((MINOR + 1))
NEXT_TAG="${MAJOR}.${NEXT_MINOR}.0"

echo "Next tag: $NEXT_TAG"
echo "GH_RELEASE_TAG=${NEXT_TAG}" >> $GITHUB_OUTPUT

DEST_TAG="${NEXT_TAG}"
fi

# ============================================
# Bundle extension assets into catalog image
# ============================================
Expand Down Expand Up @@ -231,4 +265,4 @@ popd > /dev/null

rm -rf ${TMP}

echo -e "${CHECK}${CYAN} ${IMAGE} has been successfully published.${RESET}"
echo -e "${CHECK}${CYAN} ${IMAGE} has been successfully published.${RESET}"
Loading