Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clean up github action caches #5

Merged
merged 15 commits into from
Jan 17, 2024
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest
permissions:
actions: write

steps:
- name: Checkout
Expand All @@ -56,9 +58,3 @@ jobs:
- name: Test Local Action
id: test-action
uses: ./
with:
milliseconds: 2000

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
51 changes: 9 additions & 42 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import * as main from '../src/main'
const runMock = jest.spyOn(main, 'run')

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
// const timeRegex = /^\d{2}:\d{2}:\d{2}/

// Mock the GitHub Actions core library
let debugMock: jest.SpyInstance
// let debugMock: jest.SpyInstance
let errorMock: jest.SpyInstance
let getInputMock: jest.SpyInstance
let setFailedMock: jest.SpyInstance
let setOutputMock: jest.SpyInstance
// let setFailedMock: jest.SpyInstance
// let setOutputMock: jest.SpyInstance

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()

debugMock = jest.spyOn(core, 'debug').mockImplementation()
// debugMock = jest.spyOn(core, 'debug').mockImplementation()
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
// setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
// setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})

it('sets the time output', async () => {
Expand All @@ -48,42 +48,9 @@ describe('action', () => {
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
expect(debugMock).toHaveBeenNthCalledWith(
2,
expect.stringMatching(timeRegex)
)
expect(debugMock).toHaveBeenNthCalledWith(
3,
expect.stringMatching(timeRegex)
)
expect(setOutputMock).toHaveBeenNthCalledWith(
1,
'time',
expect.stringMatching(timeRegex)
)
expect(errorMock).not.toHaveBeenCalled()
})

it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return 'this is not a number'
default:
return ''
}
})

await main.run()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
'milliseconds not a number'
)
expect(errorMock).not.toHaveBeenCalled()
})
it.todo('sets a failed status')
// Set the action's inputs as return values from core.getInput()
})
24 changes: 0 additions & 24 deletions __tests__/wait.test.ts

This file was deleted.

22 changes: 10 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
name: 'The name of your action here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: "souji-action"
description: "Clean up the GitHub Action cache"
author: "4m-mazi"

# Add your action's branding here. This will appear on the GitHub Marketplace.
# https://actions-cool.github.io/github-action-branding/
branding:
icon: 'heart'
color: 'red'
icon: "wind"
color: "purple"

# Define your inputs here.
inputs:
milliseconds:
description: 'Your input description here'
required: true
default: '1000'
repo-token:
description: "The GitHub token used to manage repository action cache"
required: false
default: ${{ github.token }}

# Define your outputs here.
outputs:
time:
description: 'Your output description here'

runs:
using: node20
Expand Down
Loading
Loading