Skip to content
Merged
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
11 changes: 8 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/package.json

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

562 changes: 251 additions & 311 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "github-slug",
"description": "GitHub Action to expose slug values of branch/tag/version inside your GitHub workflow",
"main": "src/index.js",
"type": "module",
"scripts": {
"lint": "eslint --config package.json './src/**/*.js'",
"build": "ncc build src/index.js -o dist --minify --no-cache",
"test": "jest"
"test": "node --experimental-vm-modules node_modules/.bin/jest"
},
"repository": {
"type": "git",
Expand All @@ -22,10 +23,10 @@
},
"homepage": "https://github.com/gacts/github-slug#readme",
"dependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1",
"@actions/core": "^3.0.0",
"@actions/github": "^9.0.0",
"cli-table": "^0.3.11",
"slugify": "^1.6.6"
"slugify": "^1.6.8"
},
"devDependencies": {
"@jest/globals": "^30.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/env/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @see https://git.io/Jzcq8
*/

module.exports = Object.freeze({
export default Object.freeze({
// The name of the workflow. E.g.: `tests`
GITHUB_WORKFLOW: 'GITHUB_WORKFLOW',

Expand Down
2 changes: 1 addition & 1 deletion src/env/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ function getEnv(name) {
return undefined
}

module.exports = {
export {
getEnv
}
6 changes: 3 additions & 3 deletions src/export.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {beforeEach, describe, test, expect} = require('@jest/globals')
const envGithub = require('./env/names')
const {isOnBranch, isOnTag, currentBranch, currentTag, commitHash, version} = require('./exports')
import {beforeEach, describe, test, expect} from '@jest/globals'
import envGithub from './env/names.js'
import {isOnBranch, isOnTag, currentBranch, currentTag, commitHash, version} from './exports.js'

beforeEach(() => {
Object.keys(envGithub).forEach(key => {
Expand Down
14 changes: 7 additions & 7 deletions src/exports.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const {getEnv} = require('./env/utils')
const envGithub = require('./env/names')
const {slug} = require('./formatters')
const {VersionInfo} = require('./version')
const github = require('@actions/github')
import {getEnv} from './env/utils.js'
import envGithub from './env/names.js'
import {slug} from './formatters.js'
import {VersionInfo} from './version.js'
import {context} from '@actions/github'

// references separator
const separator = '/'
Expand Down Expand Up @@ -90,7 +90,7 @@ function currentBranch() {
const eventName = getEnv(envGithub.GITHUB_EVENT_NAME)

if (eventName !== undefined) { // fix for issue https://github.com/gacts/github-slug/issues/49
const ref = github.context.payload['ref']
const ref = context.payload['ref']

switch (eventName.toLowerCase()) {
case 'delete': {// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#delete
Expand Down Expand Up @@ -294,7 +294,7 @@ function version() {
return fallbackVer
}

module.exports = {
export {
isOnBranch,
isOnTag,
currentBranch,
Expand Down
4 changes: 2 additions & 2 deletions src/formatters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const slugify = require('slugify') // link: <https://www.npmjs.com/package/slugify>
import slugify from 'slugify' // link: <https://www.npmjs.com/package/slugify>

/**
* @param {string} s
Expand All @@ -8,6 +8,6 @@ function slug(s) {
return slugify(s.replace(/[._/()#+]/g, '-'), {replacement: '-', lower: true, strict: true})
}

module.exports = {
export {
slug,
}
4 changes: 2 additions & 2 deletions src/formatters.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {describe, test, expect} = require('@jest/globals')
const {slug} = require('./formatters')
import {describe, test, expect} from '@jest/globals'
import {slug} from './formatters.js'

describe('slug', () => {
[
Expand Down
20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const core = require('@actions/core') // docs: <https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions>
const {isOnBranch, isOnTag, currentTag, currentBranch, commitHash, version} = require('./exports')
const {ActionID, Output, CLITable} = require('./utils')
const {slug} = require('./formatters')
import {getInput, setOutput, startGroup, endGroup, info, setFailed} from '@actions/core' // docs: <https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions>
import {isOnBranch, isOnTag, currentTag, currentBranch, commitHash, version} from './exports.js'
import {ActionID, Output, CLITable} from './utils.js'
import {slug} from './formatters.js'

// main action entrypoint (docs: <https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action>)
async function run() {
Expand Down Expand Up @@ -42,32 +42,32 @@ async function run() {
outputs.push(new Output('version-patch', ver.patch, 'Patch version'))
outputs.push(new Output('version-semantic', ver.semantic, 'Semantic version value'))

const toSlug = core.getInput('to-slug').trim()
const toSlug = getInput('to-slug').trim()

if (toSlug.length > 0) {
outputs.push(new Output('slug', slug(toSlug), 'A slugged version of "to-slug" input'))
}

const t = new CLITable(['Name', 'Description', 'How to use in your workflow', 'Value']), act = new ActionID

core.startGroup('Setup action')
startGroup('Setup action')
outputs.forEach((el) => {
core.setOutput(el.name, el.value)
setOutput(el.name, el.value)
t.push([
el.name,
el.description,
`${'${{ steps.' + (act.isUsable() ? act.toString() : '<this-step-id>') + '.outputs.' + el.name + ' }}'}`,
el.value,
])
})
core.endGroup()
endGroup()

core.info(t.toString())
info(t.toString())
}

// run the action
(async () => {
await run()
})().catch(error => {
core.setFailed(error.message)
setFailed(error.message)
})
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {getEnv} = require('./env/utils')
const envGithub = require('./env/names')
const Table = require('cli-table') // docs: <https://github.com/Automattic/cli-table>
import {getEnv} from './env/utils.js'
import envGithub from './env/names.js'
import Table from 'cli-table' // docs: <https://github.com/Automattic/cli-table>

class ActionID {
/** @var {string|undefined} */
Expand Down Expand Up @@ -69,7 +69,7 @@ class CLITable {
}
}

module.exports = {
export {
ActionID,
Output,
CLITable,
Expand Down
6 changes: 3 additions & 3 deletions src/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {beforeEach, describe, test, expect} = require('@jest/globals')
const envGithub = require('./env/names')
const {ActionID} = require('./utils')
import {beforeEach, describe, test, expect} from '@jest/globals'
import envGithub from './env/names.js'
import {ActionID} from './utils.js'

beforeEach(() => {
Object.keys(envGithub).forEach(key => {
Expand Down
4 changes: 2 additions & 2 deletions src/version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {slug} = require('./formatters')
import {slug} from './formatters.js'

/**
* Raw version string parser.
Expand Down Expand Up @@ -120,6 +120,6 @@ class VersionInfo {
}
}

module.exports = {
export {
VersionInfo,
}
4 changes: 2 additions & 2 deletions src/version.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {describe, test, expect} = require('@jest/globals')
const {VersionInfo} = require('./version')
import {describe, test, expect} from '@jest/globals'
import {VersionInfo} from './version.js'

describe('VersionInfo::rejectVersionPrefix', () => {
[
Expand Down
Loading