Skip to content

Commit

Permalink
Merge pull request #375 from mdb/mdb/upgrades
Browse files Browse the repository at this point in the history
Various actions and package upgrades
  • Loading branch information
mdb committed Apr 23, 2024
2 parents 36deabd + dafbd60 commit 14270e8
Show file tree
Hide file tree
Showing 10 changed files with 31,129 additions and 18,257 deletions.
37 changes: 7 additions & 30 deletions .github/workflows/test.yml
Expand Up @@ -6,11 +6,11 @@ on:
push:

jobs:
build:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3.7.0
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- run: npm install
Expand All @@ -22,48 +22,25 @@ jobs:
git diff
exit 1
fi
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3.7.0
with:
node-version-file: '.nvmrc'
- uses: ./
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
needs: build-and-test
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- 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 }}
token: ${{ secrets.GITHUB_TOKEN }}
release:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: ensure-unpublished-version
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Release
run: gh release create "$(jq -r .version package.json)" --generate-notes
env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
18
20.12.2
12 changes: 8 additions & 4 deletions __tests__/is-existing-release.test.ts
Expand Up @@ -24,9 +24,11 @@ test('finds a corresponding release tag', async () => {
})

test('does not find a corresponding release tag', async () => {
mockOctokit.rest.repos.getReleaseByTag.mockRejectedValueOnce({
status: 404
})
mockOctokit.rest.repos.getReleaseByTag = jest
.fn<() => Promise<never>>()
.mockRejectedValue({
status: 404
})

const exists = await isExistingRelease('mdb', 'terraputs', '500.0.0')

Expand All @@ -36,7 +38,9 @@ test('does not find a corresponding release tag', async () => {
test('the GitHub API responds with an error', async () => {
const response = {status: 500}

mockOctokit.rest.repos.getReleaseByTag.mockRejectedValueOnce(response)
mockOctokit.rest.repos.getReleaseByTag = jest
.fn<() => Promise<never>>()
.mockRejectedValueOnce(response)

await expect(
isExistingRelease('mdb', 'terraputs', '500.0.0')
Expand Down
15 changes: 9 additions & 6 deletions __tests__/main.test.ts
Expand Up @@ -26,9 +26,11 @@ jest.spyOn(core, 'setOutput').mockImplementation(jest.fn())
jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())

test('release does not exist', async () => {
mockOctokit.rest.repos.getReleaseByTag.mockRejectedValueOnce({
status: 404
})
mockOctokit.rest.repos.getReleaseByTag = jest
.fn<() => Promise<never>>()
.mockRejectedValueOnce({
status: 404
})

process.env['INPUT_TAG'] = tag
process.env['GITHUB_REPOSITORY'] = repo
Expand Down Expand Up @@ -57,9 +59,10 @@ test('release exists', async () => {

test('an error occurs fetching GitHub release data', async () => {
const errMessage = 'some error'
mockOctokit.rest.repos.getReleaseByTag.mockRejectedValueOnce(
new Error(errMessage)
)

mockOctokit.rest.repos.getReleaseByTag = jest
.fn<() => Promise<never>>()
.mockRejectedValueOnce(new Error(errMessage))

process.env['INPUT_TAG'] = tag
process.env['GITHUB_REPOSITORY'] = repo
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Expand Up @@ -9,5 +9,5 @@ inputs:
required: true
description: 'A GitHub access token'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'

0 comments on commit 14270e8

Please sign in to comment.