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

Do not fail if config file does not exist #214

Merged
merged 1 commit into from Nov 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main.ts
@@ -1,5 +1,5 @@
import * as core from '@actions/core'
import {readFileSync} from 'fs'
import {existsSync, readFileSync} from 'fs'
import {send, ConfigOptions} from './slack'
import * as yaml from 'js-yaml'

Expand All @@ -14,7 +14,15 @@ async function run(): Promise<void> {
core.debug(JSON.stringify(readEvent()))

const configFile = core.getInput('config', {required: false})
const config = yaml.load(readFileSync(configFile, 'utf-8'), {schema: yaml.FAILSAFE_SCHEMA}) as ConfigOptions
let config: ConfigOptions = {}
try {
core.info(`Reading config file ${configFile}...`)
if (existsSync(configFile)) {
config = yaml.load(readFileSync(configFile, 'utf-8'), {schema: yaml.FAILSAFE_SCHEMA}) as ConfigOptions
}
} catch (error) {
core.info(error.message)
}
core.debug(yaml.dump(config))

const url = process.env.SLACK_WEBHOOK_URL as string
Expand Down