sohalloran / writing-javascript-actions

https://lab.github.com/githubtraining/github-actions:-writing-javascript-actions
MIT License
0 stars 0 forks source link

Use outputs #8

Closed sohalloran closed 2 years ago

github-learning-lab[bot] commented 2 years ago

sohalloran it's time to get ready for the third action 🎉

As with the other actions we wrote, we are going to need to setup a few directories and files.

:keyboard: Activity: Configure your third action

Let's create our final project directory and install all the necessary dependencies. We will take this a step further near the end of this action and we will show you how to avoid needing to check in node_modules.

  1. Open the Terminal (Mac and Linux) or Command Prompt (Windows) on your local machine
  2. navigate to the .github/actions directory.
  3. Checkout the main branch
    git checkout main
  4. Update the contents of your Learning Lab repo to your local machine:
    git pull
  5. Checkout the action-three branch you created for this pull request.
    git checkout action-three
  6. Create a new folder for our actions files. The full path should be .github/actions/issue-maker.
    mkdir issue-maker
  7. Navigate to the issue-maker folder you just created. The full path should be .github/actions/issue-maker
    cd issue-maker
  8. Initialize a new project:
    npm init -y
  9. Install the @actions/core and @actions/github dependencies using npm:
    npm install --save @actions/core @actions/github
  10. Commit those newly added files,we will remove the need to upload node_modules in a later step. Push your changes to GitHub:
    git add .
    git commit -m 'add issue maker dependencies'
    git push

I will respond once you have pushed to this branch.

github-learning-lab[bot] commented 2 years ago

Create and edit the third actions action.yml file

Like our "hello world" action, this action will require at least one input: parameter. We need this parameter so that our JavaScript for this action has access to the output: from the joke action.

If you recall, in the my-workflow.yml file, we stated this action would take a specific input named joke: and we set it's value to the output of the previous action.

- name: create-issue
  uses: ./.github/actions/issue-maker
  with:
    joke: ${{steps.jokes.outputs.joke-output}}

Because of this, we need to define joke: as one of our inputs: for this action. Remember when we did this with the first action? It looked a little like this:

inputs:
  first-greeting:
    description: who you would like to greet in the console
    required: true
    default: Hubot

Now, we will do something similar so that our action matches what our workflow expects.

:keyboard: Activity: Create the final metadata file

💡All of the following steps take place inside of the .github/actions/issue-maker directory.

We will use the joke output, an issue-title, and the repo-token in this portion of the course as inputs: for our action.

  1. Create a file named action.yml with the following contents:

    name: "I have issues"
    
    description: "consume the output of the previous action and create a new issue in the repository"
    
    inputs:
      joke:
        description: "This will become the body of the created issue"
      issue-title:
        description: "Every issue needs a title, it's nice to supply one, even though you could do this dynamically within your code"
        default: "a joke for you"
        required: true
      repo-token:
        description: "Token with permissions to do repo things"
    
    runs:
      using: "node12"
      main: "index.js"
  2. Save the action.yml file
  3. Commit the changes and push them to GitHub:
    git add action.yml
    git commit -m 'create action.yml'
    git push

I will respond when you commit to this branch.