initial commit of actions

This commit is contained in:
2026-01-31 18:56:04 +01:00
commit 949ece5785
44660 changed files with 12034344 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
dist/
lib/
node_modules/
.mocharc.cjs

View File

@@ -0,0 +1,54 @@
{
"plugins": ["@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true
}
}

View File

@@ -0,0 +1,17 @@
# Enable dependabot, a tool to automatically propose dependency updates
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
# Maintain dependencies for npm
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
target-branch: "main"

View File

@@ -0,0 +1,16 @@
name: "build"
on:
pull_request:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
npm ci
npm run all

View File

@@ -0,0 +1,15 @@
name: Update version tag
on:
release:
types: [published]
jobs:
actions-tagger:
runs-on: ubuntu-latest
steps:
- uses: Actions-R-Us/actions-tagger@latest
with:
publish_latest: true
env:
GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}'

View File

@@ -0,0 +1,101 @@
.history
# Dependency directory
node_modules
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# OS metadata
.DS_Store
Thumbs.db
# Ignore built ts files
__tests__/runner/*
lib/**/*

View File

@@ -0,0 +1,5 @@
module.exports = {
extension: ['js', 'jsx', 'ts', 'tsx'],
spec: ['test/**.{js,ts,jsx,tsx}'],
require: 'ts-node/register'
};

View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

View File

@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 André Storhaug
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.

View File

@@ -0,0 +1,64 @@
# file-existence-action
> GitHub Action to check for file existence
![build-test](https://github.com/andstor/file-existence-action/workflows/build/badge.svg)
This is a GitHub Action to check for existence of files. It can be used for conditionally running workflow steps based on file(s) existence.
## Usage
The following example [workflow step](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow) will check for existence of the files: `package.json`, `LICENSE`, `README.md`, `foo` `bar`
```yml
- name: "Check file existence"
uses: andstor/file-existence-action@v1
with:
files: "package.json, LICENSE, README.md, foo, *.txt"
```
## Options ⚙️
The following input variables options can/must be configured:
|Input variable|Necessity|Description|Default|
|----|----|----|----|
|`files`|Required|Comma separated string with paths to files and directories to check for existence. Supports [glob paterns](https://github.com/isaacs/node-glob).||
|`ignore_case`|Optional|Ignore if a file name has upper or lower cases.|`true`|
|`follow_symbolic_links`|Optional|Indicates whether to follow symbolic links.|`true`|
|`allow_failure`|Optional|Makes the Action fail on missing files.|`false`|
## Outputs
- `files_exists`: Outputs `true` if the file(s) exists, otherwise `false`.
## Example
```yml
name: "File existence check"
on: [push, pull_request]
jobs:
file_existence:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Check file existence
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "package.json, LICENSE, README.md"
- name: File exists
if: steps.check_files.outputs.files_exists == 'true'
# Only runs if all of the files exists
run: echo All files exists!
```
## License
Copyright © 2020 [André Storhaug](https://github.com/andstor)
file-existence-action is licensed under the [MIT License](https://github.com/andstor/file-existence-ation/blob/master/LICENSE).

View File

@@ -0,0 +1,28 @@
name: 'File Existence'
description: 'GitHub Action to check for file existence'
author: 'André Storhaug'
branding:
icon: 'file-text'
color: 'green'
inputs:
files:
description: 'Comma separated string with paths to files and directories to check for existence.'
required: true
ignore_case:
description: 'Ignore if a file has upper or lower cases.'
default: false
required: false
follow_symbolic_links:
description: 'Indicates whether to follow symbolic links.'
default: true
required: false
allow_failure:
description: 'Makes the Action fail on missing files.'
default: false
required: false
outputs:
files_exists:
description: 'Wheter the file(s) exists or not.'
runs:
using: 'node12'
main: 'dist/index.js'

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
{
"name": "file-existence-action",
"version": "1.1.0",
"private": true,
"description": "GitHub Action to check for file existence",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"pack": "ncc build",
"test": "mocha",
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/andstor/file-existence-action.git"
},
"keywords": [
"actions",
"file",
"existence",
"checker"
],
"author": {
"name": "André Storhaug",
"email": "andr3.storhaug@gmail.com",
"url": "https://github.com/andstor"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/andstor/file-existence-action/issues"
},
"dependencies": {
"@actions/core": "^1.6.0",
"glob": "^7.2.0",
"tmp": "^0.2.1"
},
"devDependencies": {
"@types/chai": "^4.3.0",
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.0",
"@types/node": "^16.10.5",
"@types/tmp": "^0.2.3",
"@typescript-eslint/parser": "^5.8.1",
"@vercel/ncc": "^0.31.1",
"@zeit/ncc": "^0.20.5",
"chai": "^4.3.6",
"eslint": "^7.32.0",
"eslint-plugin-github": "^4.3.5",
"eslint-plugin-jest": "^26.1.1",
"js-yaml": "^4.1.0",
"mocha": "^9.2.1",
"prettier": "2.5.1",
"ts-node": "^10.5.0",
"typescript": "^4.4.4"
}
}

View File

@@ -0,0 +1,61 @@
import * as core from '@actions/core'
import glob from 'glob'
export async function checkExistence(pattern: string): Promise<boolean> {
const globOptions = {
follow: !(
(core.getInput('follow_symlinks') || 'true').toUpperCase() === 'FALSE'
),
nocase: (core.getInput('ignore_case') || 'false').toUpperCase() === 'TRUE'
}
return new Promise((resolve, reject) => {
glob(pattern, globOptions, (err: unknown, files: string[]) => {
if (err) {
reject(err)
} else {
resolve(files.length > 0)
}
})
})
}
async function run(): Promise<void> {
try {
const files: string = core.getInput('files', {required: true})
const failure: boolean =
(core.getInput('allow_failure') || 'false').toUpperCase() === 'TRUE'
const fileList: string[] = files
.split(',')
.map((item: string) => item.trim())
const missingFiles: string[] = []
// Check in parallel
await Promise.all(
fileList.map(async (file: string) => {
const isPresent = await checkExistence(file)
if (!isPresent) {
missingFiles.push(file)
}
})
)
if (missingFiles.length > 0) {
if (failure) {
core.setFailed(`These files don't exist: ${missingFiles.join(', ')}`)
} else {
core.info(`These files don't exist: ${missingFiles.join(', ')}`)
}
core.setOutput('files_exists', 'false')
} else {
core.info('🎉 All files exist')
core.setOutput('files_exists', 'true')
}
} catch (error) {
if (!(error instanceof Error)) {
throw error
}
core.setFailed(error.message)
}
}
run()

View File

@@ -0,0 +1,12 @@
import fs from 'fs'
import path from 'path'
import tmp from 'tmp'
tmp.setGracefulCleanup()
export function folderIsInsensitive(): boolean {
const aFolder = '.'
const t = tmp.fileSync({template: path.join(aFolder, '_tmp-XXXXXXXXX')})
const result = fs.existsSync(t.name.toUpperCase())
t.removeCallback()
return result
}

View File

@@ -0,0 +1,57 @@
import {expect} from 'chai'
import {checkExistence} from '../src/main'
import {folderIsInsensitive} from '../src/utils'
function setEnv(name: string, value: string): void {
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = value
}
describe('Case sensitivity', function () {
it('should return true for existing file', async function () {
setEnv('ignore_case', 'false')
const res = await checkExistence('test/resource/test.txt')
expect(res).to.equal(true)
})
it('should return false for uppercase file', async function () {
setEnv('ignore_case', 'false')
const res = await checkExistence('test/resource/TEST.txt')
if (folderIsInsensitive()) {
expect(res).to.equal(true)
} else {
expect(res).to.equal(false)
}
})
it('should return true for uppercase file with ignore_case true', async function () {
setEnv('ignore_case', 'true')
const res = await checkExistence('test/resource/TEST.txt')
expect(res).to.equal(true)
})
it('should return true for mIxEd case file with ignore_case true', async function () {
setEnv('ignore_case', 'true')
const res = await checkExistence('test/resource/TeSt.txt')
expect(res).to.equal(true)
})
})
describe('Glob patterns', function () {
it('should return true for **/test.txt', async function () {
setEnv('ignore_case', 'false')
const res = await checkExistence('test/**/test.txt')
expect(res).to.equal(true)
})
it('should return false for *.txt', async function () {
setEnv('ignore_case', 'false')
const res = await checkExistence('test/*.txt')
expect(res).to.equal(false)
})
it('should return true for **/*.txt', async function () {
setEnv('ignore_case', 'false')
const res = await checkExistence('test/**/*.txt')
expect(res).to.equal(true)
})
})

View File

@@ -0,0 +1 @@
This is a test file

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}