OmKumar10 / hello-github-actions

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

Create Dockerfile #2

Closed OmKumar10 closed 2 years ago

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

Nice work, you committed a Dockerfile. You'll notice at the end of the Dockerfile, we refer to an entrypoint script.

ENTRYPOINT ["/entrypoint.sh"]

The entrypoint.sh script will be run in Docker, and it will define what the action is really going to be doing.

Step 2: Add an entrypoint script

An entrypoint script must exist in our repository so that Docker has something to execute.

:keyboard: Activity: Add an entrypoint script and commit it to your branch

  1. As a part of this branch and pull request, create a file in the /action-a/ directory titled entrypoint.sh. You can do so with this quicklink

  2. Add the following content to the entrypoint.sh file:

    #!/bin/sh -l
    
    sh -c "echo Hello world my name is $INPUT_MY_NAME"
  3. Stage and commit the changes

  4. Push the changes to GitHub


I'll respond when I detect a new commit on this branch.

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

Nice work adding the entrypoint.sh script.

In entrypoint.sh, all we're doing is outputting a "Hello world" message using an environment variable called MY_NAME.

Next, we'll define the action.yml file which contains the metadata for our action.

action.yml

All actions require a metadata file that uses YAML syntax. The data in the metadata file defines the inputs, outputs and main entrypoint for your action.

Step 3: Add an action metadata file

We will use an input parameter to read in the value of MY_NAME.

:keyboard: Activity: Create action.yml

  1. As a part of this branch and pull request, create a file titled action-a/action.yml. You can do so using this quicklink or manually.

  2. Add the following content to the action.yml file:

    name: "Hello Actions"
    description: "Greet someone"
    author: "octocat@github.com"
    
    inputs:
     MY_NAME:
       description: "Who to greet"
       required: true
       default: "World"
    
    runs:
     using: "docker"
     image: "Dockerfile"
    
    branding:
     icon: "mic"
     color: "purple"
  3. Stage and commit the changes

  4. Push the changes to GitHub


I'll respond when I detect a new commit on this branch.

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

Next, we'll define a workflow that uses the GitHub Action.

Workflow Files

Workflows are defined in special files in the .github/workflows directory, named main.yml.

Workflows can execute based on your chosen event. For this lab, we'll be using the push event.

We'll break down each line of the workflow in the next step.

Step 4: Start your workflow file

First, we'll add the structure of the workflow.

:keyboard: Activity: Name and trigger your workflow

  1. Create a file titled .github/workflows/main.yml. You can do so using this quicklink or manually:
    • As a part of this branch and pull request, create a workflows directory nested inside the .github directory.
    • In the new .github/workflows/ directory, create a file titled main.yml
  2. Add the following content to the main.yml file:
    name: A workflow for my Hello World file
    on: push
  3. Stage and commit the changes
  4. Push the changes to GitHub
Trouble pushing? Click here. The `main.yml` file cannot be edited using an integration. Try editing the file using the web interface, or your command line. It is possible that you are using an integration (like GitHub Desktop or any other tool that authenticates as you and pushes on your behalf) if you receive a message like the one below: ```shell To https://github.com/your-username/your-repo.git ! [remote rejected] your-branch -> your-branch (refusing to allow an integration to update main.yml) error: failed to push some refs to 'https://github.com/your-username/your-repo.git' ```



I'll respond when I detect a new commit on this branch.

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

Nice work! :tada: You added a workflow!

Here's what it means:

Next, we need to specify a job or jobs to run.

Actions

Workflows piece together jobs, and jobs piece together steps. We'll now create a job that runs an action. Actions can be used from within the same repository, from any other public repository, or from a published Docker container image. We'll use an action that we'll define in this repository.

We'll add the block now, and break it down in the next step.

Step 5: Run an action from your workflow file

Let's add the expected action to the workflow.

:keyboard: Activity: Add an action block to your workflow file

  1. As a part of this branch and pull request, edit .github/workflows/main.yml to append the following content:
    jobs:
     build:
       name: Hello world action
       runs-on: ubuntu-latest
       steps:
         - uses: actions/checkout@v1
         - uses: ./action-a
           with:
             MY_NAME: "Mona"
  2. Click Start commit in the top right of the workflow editor
  3. Type your commit message and commit your changes directly to your branch
Trouble pushing? The `main.yml` file cannot be edited using an integration. Try editing the file using the web interface, or your command line. It is possible that you are using an integration (like GitHub Desktop or any other tool that authenticates as you and pushes on your behalf) if you receive a message like the one below: ```shell To https://github.com/your-username/your-repo.git ! [remote rejected] your-branch -> your-branch (refusing to allow an integration to update main.yml) error: failed to push some refs to 'https://github.com/your-username/your-repo.git' ```



I'll respond when I detect a new commit on this branch.

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

Nice, you just added an action block to your workflow file! Here are some important details about why each part of the block exists and what each part does.

Your action has been triggered!

Your repository now contains an action (defined in the /action-a/ folder) and a workflow (defined in the ./github/workflows/main.yml file).

This action will run any time a new commit is created or pushed to the remote repository. Since you just created a commit, the workflow should have been triggered. This might take a few minutes since it's the first time running in this repository.

Seeing your Action in action

The status of your action is shown here in the pull request (look for All checks have passed below), or you can click the "Actions" tab in your repository. From there you will see the actions that have run, and you can click on the action's "Log" link to view details.

View an action's log

Step 6: Trigger the workflow

:keyboard: Activity: See your action trigger the workflow

You've done the work, now sit back and see your action trigger the workflow!


I will respond when I detect your action has run and reported a status.

Actions can take a minute or two to run. Sometimes, I also respond too fast for the page to update! If you don't see a response from your action, wait a few seconds and refresh the page.

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

Great work merging your pull request! I created a new issue, look for my final response there.