name:"Hello World" description:"Greet someone and record the time" inputs: who-to-greet:# id of input description:"Who to greet" required:true default:"World" outputs: time:# id of output description:"The time we we greeted you" runs: using:"node12" main:"src/index.js"
try { // `who-to-greet` input defined in action metadata file const nameToGreet = core.getInput("who-to-greet"); console.log(`Hello ${nameToGreet}!`); const time = newDate().toTimeString(); core.setOutput("time", time); // Get the JSON webhook payload for the event that triggered the workflow const payload = JSON.stringify(github.context.payload, null, 2); console.log(`The event payload: ${payload}`); } catch (error) { core.setFailed(error.message); }
描述文件说明了 action 的 输入、输出、以及从哪开始运行 action。要注意的是, main 的路径是相对于 action.yml 文件,而不是相对根目录。
使用 action
在 .github/workflows/main.yml 创建一个 workflow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
on:[push]
jobs: hello_world_job: runs-on:ubuntu-latest name:Ajobtosayhello steps: # To use this repository's private action, you must check out the repository - name:Checkout uses:actions/checkout@v2 - name:Helloworldactionstep uses:./actions/release id:hello with: who-to-greet:"Mona the Octocat" # Use the output from the `hello` step - name:Gettheoutputtime run:echo"The time was ${{ steps.hello.outputs.time }}"