Skip to content

Commit

Permalink
♻️ Move to ESM (#288)
Browse files Browse the repository at this point in the history
* fix: ignore `.git` folder when checking orphaned files

* ncc

* chore: move to ESM

* less line change

* ncc

* format

* add licenses, minify dist

* rebuild dist

Co-authored-by: BetaHuhn <schiller@mxis.ch>
  • Loading branch information
balazsorban44 and BetaHuhn authored Jan 7, 2023
1 parent eb95ce4 commit 6f1bf85
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 23,439 deletions.
23,379 changes: 1 addition & 23,378 deletions dist/index.js

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@actions/core
MIT
The MIT License (MIT)

Copyright 2019 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@actions/http-client
MIT
Actions Http Client for Node.js

Copyright (c) GitHub, Inc.

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


@vercel/ncc
MIT
Copyright 2018 ZEIT, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

tunnel
MIT
The MIT License (MIT)

Copyright (c) 2012 Koichi Kobayashi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


uuid
MIT
The MIT License (MIT)

Copyright (c) 2010-2020 Robert Kieffer and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "1.19.1",
"description": "GitHub Action to keep files like Action workflows or entire directories in sync between multiple repositories.",
"main": "dist/index.js",
"type": "module",
"scripts": {
"lint": "eslint ./src",
"start": "node src/index.js",
"build": "ncc build src/index.js -o dist"
"build": "ncc build src/index.js -o dist -m --license licenses.txt"
},
"repository": {
"type": "git",
Expand Down
17 changes: 7 additions & 10 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const core = require('@actions/core')
const yaml = require('js-yaml')
const fs = require('fs-extra')
const path = require('path')
const { getInput } = require('action-input-parser')
import * as core from '@actions/core'
import * as yaml from 'js-yaml'
import * as fs from 'fs-extra'
import * as path from 'path'
import { getInput } from 'action-input-parser'

const REPLACE_DEFAULT = true
const TEMPLATE_DEFAULT = false
Expand Down Expand Up @@ -197,7 +197,7 @@ const parseFiles = (files) => {
})
}

const parseConfig = async () => {
export async function parseConfig() {
const fileContent = await fs.promises.readFile(context.CONFIG_PATH)

const configObject = yaml.load(fileContent.toString())
Expand Down Expand Up @@ -247,7 +247,4 @@ const parseConfig = async () => {
return Object.values(result)
}

module.exports = {
...context,
parseConfig
}
export default context
30 changes: 14 additions & 16 deletions src/git.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { parse } = require('@putout/git-status-porcelain')
const core = require('@actions/core')
const github = require('@actions/github')
const { GitHub, getOctokitOptions } = require('@actions/github/lib/utils')
const { throttling } = require('@octokit/plugin-throttling')
const path = require('path')
const fs = require('fs')

const {
import { parse } from '@putout/git-status-porcelain'
import * as core from '@actions/core'
import * as github from '@actions/github'
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils'
import { throttling } from '@octokit/plugin-throttling'
import * as path from 'path'
import * as fs from 'fs/promises'

import {
GITHUB_TOKEN,
IS_INSTALLATION_TOKEN,
IS_FINE_GRAINED,
Expand All @@ -21,11 +21,11 @@ const {
PR_BODY,
BRANCH_PREFIX,
FORK
} = require('./config')
} from './config'

const { dedent, execCmd } = require('./helpers')
import { dedent, execCmd } from './helpers'

class Git {
export default class Git {
constructor() {
const Octokit = GitHub.plugin(throttling)

Expand Down Expand Up @@ -196,7 +196,7 @@ class Git {

async getBlobBase64Content(file) {
const fileRelativePath = path.join(this.workingDir, file)
const fileContent = await fs.promises.readFile(fileRelativePath)
const fileContent = await fs.readFile(fileRelativePath)

return fileContent.toString('base64')
}
Expand Down Expand Up @@ -521,6 +521,4 @@ class Git {
})
this.lastCommitSha = request.data.sha
}
}

module.exports = Git
}
45 changes: 19 additions & 26 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const fs = require('fs-extra')
const readfiles = require('node-readfiles')
const { exec } = require('child_process')
const core = require('@actions/core')
const path = require('path')
const nunjucks = require('nunjucks')
import * as fs from 'fs-extra'
import readfiles from 'node-readfiles'
import { exec } from 'child_process'
import * as core from '@actions/core'
import * as path from 'path'
import * as nunjucks from 'nunjucks'

nunjucks.configure({ autoescape: true, trimBlocks: true, lstripBlocks: true })

// From https://github.com/toniov/p-iteration/blob/master/lib/static-methods.js - MIT © Antonio V
const forEach = async (array, callback) => {
export async function forEach(array, callback) {
for (let index = 0; index < array.length; index++) {
// eslint-disable-next-line callback-return
await callback(array[index], index, array)
}
}

// From https://github.com/MartinKolarik/dedent-js/blob/master/src/index.ts - MIT © 2015 Martin Kolárik
const dedent = function(templateStrings, ...values) {
export function dedent(templateStrings, ...values) {
const matches = []
const strings = typeof templateStrings === 'string' ? [ templateStrings ] : templateStrings.slice()
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, '')
Expand All @@ -42,7 +42,7 @@ const dedent = function(templateStrings, ...values) {
return string
}

const execCmd = (command, workingDir, trimResult = true) => {
export function execCmd(command, workingDir, trimResult = true) {
core.debug(`EXEC: "${ command }" IN ${ workingDir }`)
return new Promise((resolve, reject) => {
exec(
Expand All @@ -60,22 +60,24 @@ const execCmd = (command, workingDir, trimResult = true) => {
})
}

const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/'
export function addTrailingSlash(str) {
return str.endsWith('/') ? str : str + '/'
}

const pathIsDirectory = async (path) => {
export async function pathIsDirectory(path) {
const stat = await fs.lstat(path)
return stat.isDirectory()
}

const write = async (src, dest, context) => {
export async function write(src, dest, context) {
if (typeof context !== 'object') {
context = {}
}
const content = nunjucks.render(src, context)
await fs.outputFile(dest, content)
}

const copy = async (src, dest, isDirectory, file) => {
export async function copy(src, dest, isDirectory, file) {
const deleteOrphaned = isDirectory && file.deleteOrphaned

const filterFunc = (file) => {
Expand Down Expand Up @@ -154,22 +156,13 @@ const copy = async (src, dest, isDirectory, file) => {
}
}

const remove = async (src) => {
export async function remove(src) {

core.debug(`RM: ${ src }`)

return fs.remove(src)
}

const arrayEquals = (array1, array2) => Array.isArray(array1) && Array.isArray(array2) && array1.length === array2.length && array1.every((value, i) => value === array2[i])

module.exports = {
forEach,
dedent,
addTrailingSlash,
pathIsDirectory,
execCmd,
copy,
remove,
arrayEquals
}
export function arrayEquals(array1, array2) {
return Array.isArray(array1) && Array.isArray(array2) && array1.length === array2.length && array1.every((value, i) => value === array2[i])
}
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const core = require('@actions/core')
const fs = require('fs')
import * as core from '@actions/core'
import * as fs from 'fs'

const Git = require('./git')
const { forEach, dedent, addTrailingSlash, pathIsDirectory, copy, remove, arrayEquals } = require('./helpers')
import Git from './git'
import { forEach, dedent, addTrailingSlash, pathIsDirectory, copy, remove, arrayEquals } from './helpers'

import { parseConfig, default as config } from './config'

const {
parseConfig,
COMMIT_EACH_FILE,
COMMIT_PREFIX,
PR_LABELS,
Expand All @@ -20,9 +21,9 @@ const {
FORK,
REVIEWERS,
TEAM_REVIEWERS
} = require('./config')
} = config

const run = async () => {
async function run() {
// Reuse octokit for each repo
const git = new Git()

Expand Down Expand Up @@ -216,7 +217,6 @@ const run = async () => {
}

run()
.then(() => {})
.catch((err) => {
core.setFailed(err.message)
core.debug(err)
Expand Down

0 comments on commit 6f1bf85

Please sign in to comment.