diff --git a/.github/workflows/operator-hub-release.yaml b/.github/workflows/operator-hub-release.yaml index a1c27fe..09df8a6 100644 --- a/.github/workflows/operator-hub-release.yaml +++ b/.github/workflows/operator-hub-release.yaml @@ -9,9 +9,28 @@ on: repo: type: string required: true + release_ref: + type: string + required: true secrets: BOT_TOKEN: required: true + workflow_dispatch: + inputs: + org: + description: Organization that owns the target repository + required: true + type: string + default: k8s-operatorhub + repo: + description: Target repository name + required: true + type: string + default: community-operators + release_ref: + description: Release tag to publish from (for example v0.4.0) + required: true + type: string permissions: contents: read @@ -26,12 +45,26 @@ jobs: contents: write runs-on: ubuntu-latest steps: - - name: Set version from tag + - name: Validate and prepare release values + id: prepare_release env: - TAG: ${{ github.ref_name }} + RELEASE_REF_INPUT: ${{ inputs.release_ref }} run: | - TAG=${TAG:1} - echo "VERSION=${TAG}" >> $GITHUB_ENV + TAG="${RELEASE_REF_INPUT#refs/tags/}" + VERSION="${TAG#v}" + + if [ -z "${TAG}" ]; then + echo "A release tag is required. Pass release_ref (for example v0.4.0)." >&2 + exit 1 + fi + + if ! git ls-remote --exit-code --tags "https://github.com/${GITHUB_REPOSITORY}.git" "refs/tags/${TAG}" >/dev/null; then + echo "release_ref must be an existing tag in ${GITHUB_REPOSITORY}: ${TAG}" >&2 + exit 1 + fi + + echo "release_ref=${TAG}" >> "$GITHUB_OUTPUT" + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" - name: Sync fork env: @@ -51,7 +84,7 @@ jobs: uses: actions/checkout@v6 with: repository: ${{ github.repository }} - ref: ${{ github.ref_name }} + ref: ${{ steps.prepare_release.outputs.release_ref }} path: tmp/ - name: Set up Go @@ -65,6 +98,7 @@ jobs: - name: Copy bundle to versioned directory run: | + VERSION="${{ steps.prepare_release.outputs.version }}" mkdir -p operators/${OPERATOR_NAME}/${VERSION} cp -R tmp/bundle/manifests operators/${OPERATOR_NAME}/${VERSION}/ cp -R tmp/bundle/metadata operators/${OPERATOR_NAME}/${VERSION}/ @@ -74,6 +108,7 @@ jobs: - name: Create pull request env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} + VERSION: ${{ steps.prepare_release.outputs.version }} run: | git config user.name ${{ env.BOT_USER }} git config user.email ${{ env.BOT_USER }}@users.noreply.github.com diff --git a/.github/workflows/publish-operator-hub.yaml b/.github/workflows/publish-operator-hub.yaml index fdba0b0..431f3b5 100644 --- a/.github/workflows/publish-operator-hub.yaml +++ b/.github/workflows/publish-operator-hub.yaml @@ -15,6 +15,7 @@ jobs: with: org: k8s-operatorhub repo: community-operators + release_ref: ${{ github.event.release.tag_name }} secrets: # NOTE: BOT_TOKEN is a PAT (repo scope) for the persesbot account # Required to sync and push to persesbot's fork of community-operators