const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');

try {
  // name is from action.yaml (the input)
  const name = core.getInput('name');  
  console.log(`Arg received from index.js: ${name}`);
  
  console.log('Workdir from index.js:');
  fs.readdirSync('.').forEach(file => {
    console.log(file);
  });

  // This is how we can get the github context in the action
  const payload = JSON.stringify(github.context.payload, undefined, 2); 
  console.log(`The event payload: ${payload}`);
  
  fs.writeFileSync('name.txt', name);
  core.setOutput('processed-name', name);
} catch (error) {
  core.setFailed(error.message);
}
