Skip to content

Commit

Permalink
DEVOPS-571: ability to specify the release tag to publish from
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhmg committed Nov 15, 2024
1 parent 50f777d commit ef1a1e3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
42 changes: 25 additions & 17 deletions .github/actions/reusable-get_draft_release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,46 @@ inputs:
description: "The GitHub token (secret)"
required: true
type: string
existing-release:
description: "The tag corresponding to the desired release. If empty, will get it from github.ref"
required: false
type: string

outputs:
release-name:
description: "The release name: newly created or existing one at the current tag"
value: ${{ steps.get-or-draft-release.outputs.release-name}}
version-tag:
description: "The name of the current version tag"
value: ${{ steps.get-or-draft-release.outputs.version-tag}}
release-tag:
description: "The tag for the newly created or existing release (same value as `inputs.existing-release` if provided)"
value: ${{ steps.get-or-draft-release.outputs.release-tag || steps.get-existing-release.outputs.release-tag }}

runs:
using: "composite"
steps:
- name: Get or Draft Release
- run: gh --version
- name: Get existing release
id: get-existing-release
if: ${{ inputs.existing-release }}
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: >
gh release view ${{ inputs.release-tag }}
&& echo "release-tag=${{ inputs.existing-release }}" >> $GITHUB_OUTPUT
- name: Get or Draft release
id: get-or-draft-release
if: ${{ !inputs.existing-release }}
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: >
[[ "$GITHUB_REF" != refs/tags/v* ]]
&& { echo "Error: workflow is not running on a version tag" >&2; exit 1; }
|| tag_name=${GITHUB_REF#refs/tags/}
gh --version
tag_name=${GITHUB_REF#refs/tags/}
# if no release is found, draft a new one (as pre-release if the tag says to)
gh release view $tag_name 2> /dev/null
|| new_release_url=$( gh release create --draft
|| gh release create --draft
$( echo $tag_name | grep -i -q '^v[0-9]\+\(\.[0-9]\+\)\+-[a-z]' && echo --prerelease )
-t $tag_name
$tag_name )
[[ $new_release_url ]] && (echo "release-name=${new_release_url##https*/}" >> $GITHUB_OUTPUT)
|| (echo "release-name=$tag_name" >> $GITHUB_OUTPUT)
$tag_name
echo "version-tag=$tag_name" >> $GITHUB_OUTPUT
echo "release-tag=$tag_name" >> $GITHUB_OUTPUT
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release upload --clobber ${{ steps.get-draft-release.outputs.release-name }} download-artifact/*
run: gh release upload --clobber ${{ steps.get-draft-release.outputs.release-tag }} download-artifact/*
2 changes: 1 addition & 1 deletion .github/workflows/reusable-python-publish_pypi_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release upload --clobber ${{ steps.get-draft-release.outputs.release-name }} download-artifact/*
run: gh release upload --clobber ${{ steps.get-draft-release.outputs.release-tag }} download-artifact/*
7 changes: 6 additions & 1 deletion .github/workflows/reusable-python-release_conda_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
description: 'Matrix of virtual repository names to publish on (eg. ["public-conda-prod"])'
required: true
type: string
release-tag:
description: 'Tag for the existing (draft) release to download assets from'
required: true
type: string

secrets:
JFROG_ARTIFACTORY_URL:
Expand Down Expand Up @@ -35,11 +39,12 @@ jobs:
id: get-draft-release
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
existing-release: ${{ inputs.release-tag }}
- name: Download release assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ steps.get-draft-release.outputs.version-tag }}
RELEASE_TAG: ${{ steps.get-draft-release.outputs.release-tag }}
run: |
mkdir -p download-assets
cd download-assets
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/reusable-python-release_pypi_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
description: 'Matrix of virtual repository names to publish on (eg. ["public-pypi-prod"])'
required: true
type: string
release-tag:
description: 'Tag for the existing (draft) release to download assets from'
required: true
type: string

secrets:
JFROG_ARTIFACTORY_URL:
Expand Down Expand Up @@ -43,11 +47,12 @@ jobs:
id: get-draft-release
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
existing-release: ${{ inputs.release-tag }}
- name: Download release assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ steps.get-draft-release.outputs.version-tag }}
RELEASE_TAG: ${{ steps.get-draft-release.outputs.release-tag }}
run: |
mkdir -p download-assets
cd download-assets
Expand Down

0 comments on commit ef1a1e3

Please sign in to comment.