Skip to content

Commit

Permalink
Merge pull request #183 from mdb/additional-output
Browse files Browse the repository at this point in the history
Add logging and explicit output
  • Loading branch information
mdb committed Aug 9, 2022
2 parents 10bc745 + 5321e20 commit cac92ed
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,26 @@ jobs:
with:
tag: 0.0.0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./
with:
tag: 0.0.0
token: ${{ secrets.GITHUB_TOKEN }}
ensure-unpublished-version:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- name: Get package.json version
run: echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_ENV

# invoke the action with fail: false
- uses: ./
with:
tag: ${{ env.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
fail: false

# invoke the action with fail: true
- uses: ./
with:
tag: ${{ env.VERSION }}
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

A GitHub Action that checks if a given GitHub release tag already exists.

`ensure-unpublished-release-action` succeeds if the provided release tag
is unique and does not already exist, and fails if the tag has already
been published as a GitHub release.
In default configuration, `ensure-unpublished-release-action` succeeds if the provided release tag
is unique and does not already exist, and fails if the tag has already been published as a GitHub release.

The action produces an `exists` output whose value is `true` or `false`.

## Usage

Expand Down
3 changes: 2 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const repo = 'mdb/terraputs'
const tag = '500.0.0'

jest.spyOn(core, 'info').mockImplementation(jest.fn())
jest.spyOn(core, 'setOutput').mockImplementation(jest.fn())
jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())

test('release does not exist', async () => {
Expand All @@ -38,6 +39,7 @@ test('release does not exist', async () => {
expect(core.info).toHaveBeenCalledWith(
`${repo} release tag ${tag} does not exist`
)
expect(core.setOutput).toHaveBeenCalledWith('exists', false)
})

test('release exists', async () => {
Expand All @@ -51,7 +53,6 @@ test('release exists', async () => {
expect(core.setFailed).toHaveBeenCalledWith(
`${repo} release tag ${tag} exists`
)
expect(core.info).not.toHaveBeenCalled()
})

test('an error occurs fetching GitHub release data', async () => {
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ensure-unpublished-release-action",
"version": "0.0.15",
"version": "0.1.0",
"private": true,
"description": "Check that a given GitHub release tag does not already exist",
"main": "lib/main.js",
Expand Down
12 changes: 10 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ export const run = async (): Promise<void> => {
try {
const tag: string = core.getInput('tag')
const exists = await isExistingRelease(owner, repo, tag)
if (exists) core.setFailed(`${owner}/${repo} release tag ${tag} exists`)
if (!exists) core.info(`${owner}/${repo} release tag ${tag} does not exist`)

if (exists) {
core.setOutput('exists', true)
core.setFailed(`${owner}/${repo} release tag ${tag} exists`)
}

if (!exists) {
core.setOutput('exists', false)
core.info(`${owner}/${repo} release tag ${tag} does not exist`)
}
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down

0 comments on commit cac92ed

Please sign in to comment.