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

Convert to ESM #143

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

50 changes: 0 additions & 50 deletions .github/linters/.eslintrc.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .github/linters/.markdown-lint.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ jobs:
runs-on: ubuntu-latest

steps:
# Checkout the repository.
- name: Checkout
id: checkout
uses: actions/checkout@v4

# Setup Node.js using the version specified in `.node-version`.
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

# Install dependencies using `npm ci`.
- name: Install Dependencies
id: install
run: npm ci

# Build the `dist/` directory.
- name: Build dist/ Directory
id: build
run: npm run bundle
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Continuous Integration

on:
pull_request:
branches:
- main
push:
branches:
- main
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# This workflow will lint the entire codebase using the
# `super-linter/super-linter` action.
#
# For more information, see the super-linter repository:
# https://github.com/super-linter/super-linter
name: Lint Codebase

on:
pull_request:
branches:
- main
push:
branches:
- main
Expand All @@ -17,30 +24,37 @@ jobs:
runs-on: ubuntu-latest

steps:
# Checkout the repository.
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Setup Node.js using the version specified in `.node-version`.
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

# Install dependencies using `npm ci`.
- name: Install Dependencies
id: install
run: npm ci

# Lint the codebase using the `super-linter/super-linter` action.
- name: Lint Codebase
id: super-linter
uses: super-linter/super-linter/slim@v7
env:
DEFAULT_BRANCH: main
FILTER_REGEX_EXCLUDE: dist/**/*
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: ${{ github.workspace }}
VALIDATE_ALL_CODEBASE: true
VALIDATE_JAVASCRIPT_ES: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_JSCPD: false
VALIDATE_JSON: false
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ __tests__/runner/*

# IDE files
.idea
.vscode
*.code-workspace
24 changes: 24 additions & 0 deletions .markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See: https://github.com/DavidAnson/markdownlint

# Unordered list style
MD004:
style: dash

# Disable line length for tables
MD013:
tables: false

# Ordered list item prefix
MD029:
style: one

# Spaces after list markers
MD030:
ul_single: 1
ol_single: 1
ul_multi: 1
ol_multi: 1

# Code block style
MD046:
style: fenced
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.6.0
20.9.0
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
dist/
node_modules/
coverage/
coverage/
16 changes: 0 additions & 16 deletions .prettierrc.json

This file was deleted.

16 changes: 16 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See: https://prettier.io/docs/en/configuration

printWidth: 80
tabWidth: 2
useTabs: false
semi: false
singleQuote: true
quoteProps: as-needed
jsxSingleQuote: false
trailingComma: none
bracketSpacing: true
bracketSameLine: true
arrowParens: always
proseWrap: always
htmlWhitespaceSensitivity: css
endOfLine: lf
2 changes: 2 additions & 0 deletions .github/linters/.yaml-lint.yml → .yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# See: https://yamllint.readthedocs.io/en/stable/

rules:
document-end: disable
document-start:
Expand Down
6 changes: 5 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Repository CODEOWNERS
############################################################################
# Repository CODEOWNERS #
# Order is important! The last matching pattern takes the most precedence. #
############################################################################

# Default owners, unless a later match takes precedence.
* @actions/actions-oss-maintainers
12 changes: 12 additions & 0 deletions __fixtures__/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This file is used to mock the `@actions/core` module in tests.
*/
import { jest } from '@jest/globals'

export const debug = jest.fn()
export const error = jest.fn()
export const info = jest.fn()
export const getInput = jest.fn()
export const setOutput = jest.fn()
export const setFailed = jest.fn()
export const warning = jest.fn()
5 changes: 5 additions & 0 deletions __fixtures__/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const context = {
payload: {
actor: 'mona'
}
}
18 changes: 0 additions & 18 deletions __tests__/index.test.js

This file was deleted.

82 changes: 22 additions & 60 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,52 @@
/**
* Unit tests for the action's main functionality, src/main.js
*/
const core = require('@actions/core')
const github = require('@actions/github')
const main = require('../src/main')
import { afterEach, beforeEach, jest } from '@jest/globals'
const core = await import('../__fixtures__/core')
const github = await import('../__fixtures__/github')

// Mock the GitHub Actions core library
const infoMock = jest.spyOn(core, 'info').mockImplementation()
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
jest.unstable_mockModule('@actions/core', () => core)
jest.unstable_mockModule('@actions/github', () => github)

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
const main = await import('../src/main')

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

it('sets the time output', async () => {
// Mock the action's inputs
getInputMock.mockImplementation(name => {
switch (name) {
case 'who-to-greet':
return 'World'
default:
return ''
}
})
core.getInput.mockReturnValueOnce('World')

// Mock the action's payload
github.context.payload = {}
github.context.payload = {
actor: 'mona'
}
})

afterEach(() => {
jest.resetAllMocks()
})

it('sets the time output', async () => {
await main.run()

expect(runMock).toHaveReturned()
expect(setOutputMock).toHaveBeenCalledWith('time', expect.any(String))
expect(core.setOutput).toHaveBeenCalledWith('time', expect.any(String))
})

it('logs the event payload', async () => {
// Mock the action's inputs
getInputMock.mockImplementation(name => {
switch (name) {
case 'who-to-greet':
return 'World'
default:
return ''
}
})

// Mock the action's payload
github.context.payload = {
actor: 'mona'
}

await main.run()

expect(runMock).toHaveReturned()
expect(infoMock).toHaveBeenCalledWith(
expect(core.info).toHaveBeenCalledWith(
`The event payload: ${JSON.stringify(github.context.payload, null, 2)}`
)
})

it('sets a failed status', async () => {
// Mock the action's inputs
getInputMock.mockImplementation(name => {
switch (name) {
case 'who-to-greet':
throw new Error('Something went wrong...')
default:
return ''
}
// Mock a failure
core.getInput.mockReset().mockImplementation((name) => {
throw new Error('Something went wrong...')
})

// Mock the action's payload
github.context.payload = {
actor: 'mona'
}

await main.run()

expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith('Something went wrong...')
expect(core.setFailed).toHaveBeenCalledWith('Something went wrong...')
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading