Skip to content

Commit

Permalink
🚀 Added prereleases
Browse files Browse the repository at this point in the history
More stabilization
  • Loading branch information
elgohr committed Nov 2, 2024
1 parent 510be4f commit ed17bd4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: MyReleaseMessage
tag: MyTag
```
## Mandatory Arguments
Expand All @@ -34,10 +33,31 @@ jobs:
## Optional Arguments

### workdir
`workdir` can be used to specify a directory that contains the repository to be published.
`workdir` can be used to specify a directory that contains the repository to be published.

```yaml
with:
title: MyReleaseMessage
workdir: myDirectoryName
```

### tag
`tag` can be used to set the tag of the release
`tag` can be used to set the tag of the release.

```yaml
with:
title: MyReleaseMessage
tag: MyTag
```

### prerelease
`prerelease` is used to publish a prerelease.

```yaml
with:
title: MyReleaseMessage
prerelease: true
```

## Notes

Expand All @@ -55,7 +75,7 @@ permissions:

to the concrete job creating the release. For more details see the [documentation on token permissions.](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token)

### Use with GitHub Enterprise
### GitHub Enterprise

To publish your release to self-hosted GitHub Enterprise, include `GH_ENTERPRISE_TOKEN` and `GH_HOST` as environment variables.
For example:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
tag:
description: "The tag of the release to publish"
required: false
prerelease:
description: "Publishes a prerelease"
required: false

runs:
using: 'composite'
Expand All @@ -25,3 +28,4 @@ runs:
INPUT_TITLE: ${{ inputs.title }}
INPUT_WORKDIR: ${{ inputs.workdir }}
INPUT_TAG: ${{ inputs.tag }}
INPUT_PRERELEASE: ${{ inputs.prerelease }}
31 changes: 24 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/usr/bin/env sh

if [ ! -z "${INPUT_WORKDIR}" ]; then
cd "${INPUT_WORKDIR}"
fi
main() {
if uses "${INPUT_WORKDIR}"; then
cd "${INPUT_WORKDIR}"
fi

if [ -z "${INPUT_TAG}" ]; then
INPUT_TAG="release-$(date +%Y%m%d%H%M%S)"
fi
if ! uses "${INPUT_TAG}"; then
INPUT_TAG="release-$(date +%Y%m%d%H%M%S)"
fi

gh release create $INPUT_TAG -t "${INPUT_TITLE}" --generate-notes
OPTIONS=""
if usesBoolean "${INPUT_PRERELEASE}"; then
OPTIONS="${OPTIONS} --prerelease"
fi

gh release create $INPUT_TAG -t "${INPUT_TITLE}" --generate-notes"${OPTIONS}"
}

uses() {
[ ! -z "${1}" ]
}

usesBoolean() {
[ ! -z "${1}" ] && [ "${1}" = "true" ]
}

main
19 changes: 19 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ setup(){
teardown() {
unset INPUT_WORKDIR
unset INPUT_TAG
unset INPUT_PRERELEASE
}

@test "it creates a release" {
Expand All @@ -41,6 +42,24 @@ teardown() {
expectMockCalledIs "/usr/local/mock/gh release create ${INPUT_TAG} -t TITLE --generate-notes"
}

@test "it creates a prerelease" {
export INPUT_TAG="TAG"
export INPUT_PRERELEASE="true"

run /entrypoint.sh

expectMockCalledIs "/usr/local/mock/gh release create ${INPUT_TAG} -t TITLE --generate-notes --prerelease"
}

@test "it doesn't create a prerelease on false" {
export INPUT_TAG="TAG"
export INPUT_PRERELEASE="false"

run /entrypoint.sh

expectMockCalledIs "/usr/local/mock/gh release create ${INPUT_TAG} -t TITLE --generate-notes"
}

expectMockCalledIs() {
local expected=$(echo "${1}" | tr -d '\n')
local got=$(cat mockArgs | tr -d '\n')
Expand Down

0 comments on commit ed17bd4

Please sign in to comment.