Coder Social home page Coder Social logo

intro-to-actions's Introduction

Hello GitHub Actions

Create a GitHub Action and use it in a workflow.

Step 1: Create a workflow file

Welcome to "Hello GitHub Actions"! 👋

What is GitHub Actions: Actions are a flexible way to automate nearly every aspect of your team's software workflow. You can automate testing, continuously deploy, review code, manage issues and pull requests, and much more. The best part, these workflows are stored as code in your repository and easily shared and reused across teams. To learn more, check out the GitHub Actions feature page, or the GitHub Actions documentation.

First, we'll define a workflow that uses the action.

What is a workflow: Workflows are defined in special files in the .github/workflows directory. Workflows can execute based on your chosen event. For this lab, we'll be using the push event.

We went ahead and made a branch and pull request for you.

⌨️ Activity: Create a workflow file

  1. Open a new browser tab, and work on the steps in your second tab while you read the instructions in this tab.
  2. Open the pull request from the emoji-workflow branch.
  3. Add a file at .github/workflows/emoji.yml on the emoji-workflow branch.
  4. Add the following content to the emoji.yml file:
    name: Check emoji shortcode
    on: push
  5. Commit the changes.
  6. Wait about 20 seconds then refresh this page for the next step.

Step 2: Add a job to your workflow file

Nice work! 🎉 You added a workflow!

Here's what it means:

  • name: A workflow for my Hello World file gives your workflow a name. This name appears on any pull request or in the Actions tab.
  • on: push indicates that your workflow will execute anytime code is pushed to your repository.

Next, we need to specify jobs to run.

What is a job: Workflows have jobs, and jobs have steps.

In this step, we will add a "build" job. We will specify ubuntu-latest as the fastest and cheapest job runner available.

⌨️ Activity: Add a job to your workflow file

  1. Update emoji.yml in the emoji-workflow branch to:
    name: Check emoji shortcode
    on: push
    jobs:
      build:
        name: Check emoji shortcode
        runs-on: ubuntu-latest
  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.
  4. Wait about 20 seconds then refresh this page for the next step.

Step 3: Add actions to your workflow file

Nice work adding a job to your workflow! 💃

Workflows have jobs, and jobs have steps. So now we'll add steps.

What are steps: Action steps will run during our job in order. Each step must pass for the next step to run. Action steps can be used from within the same repository, from any other public repository, or from a published Docker container image.

In our action,

  1. We will git checkout the code, using a pre-built checkout action.
  2. We'll run a bash script to check Markdown files.
  3. We'll fail (exit 1) if any Markdown file contains an emoji without using emoji shortcodes.

⌨️ Activity: Add actions to your workflow file

  1. Update emoji.yml in the emoji-workflow branch to:
    name: Check emoji shortcode
    on: push
    jobs:
      build:
        name: Check emoji shortcode
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - run: |
              if LC_ALL=C grep -R '[^ -~]' *.md; then
                echo "Use emoji shortcodes instead!"
                echo "See https://github.com/ikatyang/emoji-cheat-sheet/blob/master/README.md"
                exit 1
              fi
  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.
  4. Wait about 20 seconds then refresh this page for the next step.

Step 4: Merge your workflow file

You're now able to write and run Actions workflows! ❤️

Merge this pull request so the action will be a part of the main branch.

⌨️ Activity: Merge your workflow file

  1. Merge the pull request from branch emoji-workflow.
  2. Delete your emoji-workflow branch (optional).
  3. Wait about 20 seconds then refresh this page for the next step.

Step 5: Trigger the workflow

You've now got a fully functioning workflow! 😄

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.

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

⌨️ Activity: Trigger the workflow

  1. Make a new branch: test-workflow.
  2. Commit any change to your branch, such as adding an emoji to your README.md file.
  3. Open a pull request with branch: test-workflow.
  4. See your action run on your pull request.
  5. Wait about 20 seconds then refresh this page for the next step.

Finish

Congratulations friend, you've completed this course!

celebrate

Here's a recap of all the tasks you've accomplished in your repository:

  • You've created your first GitHub Actions workflow.
  • You learned where to make your workflow file.
  • You created an event trigger, a job, and steps for your workflow.
  • You're ready to automate anything you can dream of.

What's next?


Get help: Post in our discussion boardReview the GitHub status page

© 2022 GitHub • Code of ConductCC-BY-4.0 License

intro-to-actions's People

Contributors

davidjarzebowski avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.