|
| 1 | +# Uploads build artifacts to a tagged or continuous GitHub release |
| 2 | +# Inspired by GH cli docs https://cli.github.com/manual/gh_release |
| 3 | + |
| 4 | +name: "Upload to Release or Continuous" |
| 5 | +description: "Uploads build artifacts to a tagged or continuous GitHub release" |
| 6 | +inputs: |
| 7 | + artifacts: |
| 8 | + description: "Path or glob to artifacts to upload" |
| 9 | + required: true |
| 10 | + release_name: |
| 11 | + description: "Release name for non-tag builds (default: continuous)" |
| 12 | + required: false |
| 13 | + default: "continuous" |
| 14 | +runs: |
| 15 | + using: "composite" |
| 16 | + steps: |
| 17 | + - name: Determine release tag |
| 18 | + id: tag |
| 19 | + shell: bash |
| 20 | + run: | |
| 21 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 22 | + echo "release_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 23 | + else |
| 24 | + # i.e. continuous |
| 25 | + echo "release_tag=${{ inputs.release_name }}" >> $GITHUB_OUTPUT |
| 26 | + fi |
| 27 | +
|
| 28 | + - name: Create or update release |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + tag="${{ steps.tag.outputs.release_tag }}" |
| 32 | + build_date=$(date -u +"%Y-%m-%d %H:%M UTC") |
| 33 | + notes="Automated build on ${build_date} from ${GITHUB_SHA}" |
| 34 | +
|
| 35 | + if gh release view "$tag" &>/dev/null; then |
| 36 | + # only update the "continous" tag |
| 37 | + # so we don't break the release notes for other tags |
| 38 | + if [[ "$tag" == "${{ inputs.release_name }}" ]]; then |
| 39 | + echo "Updating existing release: $tag" |
| 40 | + gh release edit "$tag" --notes "$notes" |
| 41 | + fi |
| 42 | + else |
| 43 | + echo "Creating release: $tag" |
| 44 | + gh release create "$tag" --prerelease --title "$tag" --notes "$notes" |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Upload artifacts |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + # --clobber will overwrite existing artifacts |
| 51 | + gh release upload "${{ steps.vars.outputs.release_tag }}" ${{ inputs.artifacts }} --clobber |
0 commit comments