Skip to content

Commit

Permalink
Merge pull request #214 from act10ns/fix-no-config-file
Browse files Browse the repository at this point in the history
fix: Do not fail if config file does not exist
  • Loading branch information
satterly committed Nov 7, 2021
2 parents 9baa775 + b63433f commit 2dc791a
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 2dc791a

Please sign in to comment.