Promote dev version tag to release version tag #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Promote dev version tag to release version tag | |
| description: Promote vX.Y.Z-dev (built via the dev workflow) to vX.Y.Z and optional aliases | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release-version: | |
| description: "Targeted release version tag (e.g. 'v2.5.1')" | |
| type: string | |
| required: true | |
| promote-latest: | |
| description: "Also promote to 'latest' tag (only enable if promoting the newest beets release)" | |
| type: boolean | |
| required: false | |
| default: false | |
| jobs: | |
| promote-tag: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| PROJECT_NAME: beets | |
| steps: | |
| - name: Validate selections | |
| shell: bash -euo pipefail {0} | |
| id: prepare | |
| env: | |
| RELEASE_VERSION: ${{ inputs.release-version }} | |
| PROMOTE_LATEST: ${{ inputs.promote-latest }} | |
| run: | | |
| if ! [[ "$RELEASE_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "::error::RELEASE_VERSION must match v<digit>.<digit>.<digit> (e.g. v2.5.1)" | |
| exit 1 | |
| fi | |
| source_tag="${RELEASE_VERSION}-dev" | |
| tags=("${RELEASE_VERSION}") | |
| if [[ "${PROMOTE_LATEST}" == "true" ]]; then | |
| tags+=("latest") | |
| fi | |
| { | |
| printf 'source-tag=%s\n' "${source_tag}" | |
| printf 'tags<<EOF\n' | |
| for tag in "${tags[@]}"; do | |
| printf '%s\n' "$tag" | |
| done | |
| printf 'EOF\n' | |
| } >> "${GITHUB_OUTPUT}" | |
| - uses: docker/setup-buildx-action@v3 | |
| - name: DockerHub login | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: GitHub Container Registry login | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Promote tags | |
| shell: bash -euo pipefail {0} | |
| env: | |
| DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }} | |
| PROJECT_NAME: ${{ env.PROJECT_NAME }} | |
| GH_OWNER: ${{ github.repository_owner }} | |
| SOURCE_TAG: ${{ steps.prepare.outputs.source-tag }} | |
| TARGET_TAGS: ${{ steps.prepare.outputs.tags }} | |
| run: | | |
| owner_lower=$(printf '%s' "$GH_OWNER" | tr '[:upper:]' '[:lower:]') | |
| hub_source="${DOCKERHUB_USERNAME}/${PROJECT_NAME}:${SOURCE_TAG}" | |
| ghcr_source="ghcr.io/${owner_lower}/${PROJECT_NAME}:${SOURCE_TAG}" | |
| mkdir -p tags | |
| printf '%s\n' "$TARGET_TAGS" > tags/list | |
| echo "Validating source manifest on DockerHub: ${hub_source}" | |
| docker buildx imagetools inspect "${hub_source}" > /dev/null | |
| echo "Validating source manifest on GHCR: ${ghcr_source}" | |
| docker buildx imagetools inspect "${ghcr_source}" > /dev/null | |
| while IFS= read -r tag; do | |
| [ -n "$tag" ] || continue | |
| echo "Promoting DockerHub tag: ${hub_source} -> ${tag}" | |
| docker buildx imagetools create \ | |
| --tag "${DOCKERHUB_USERNAME}/${PROJECT_NAME}:${tag}" \ | |
| "${hub_source}" | |
| echo "Promoting GHCR tag: ${ghcr_source} -> ${tag}" | |
| docker buildx imagetools create \ | |
| --tag "ghcr.io/${owner_lower}/${PROJECT_NAME}:${tag}" \ | |
| "${ghcr_source}" | |
| done < tags/list |