Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lession learned - How to build a GitHub Action

Lession learned - How to build a GitHub Action

Given at a company internal thundertalk.

Me and a few colleagues participated at the GitHub Actions Hackathon 2020.
We didn't know how to build a GitHub Action.
This slides gives you a roughly overview how you can build a GitHub Action by yourself.

Stefan M.

April 30, 2020
Tweet

More Decks by Stefan M.

Other Decks in Technology

Transcript

  1. How to build a GitHub Action

    View Slide

  2. About GitHub Actions (consumer side)
    • CI/CD
    • 4 runners
    • macOS, Windows, Linux and self hosted
    • Run on real machines
    • There is pre installed software
    • There are environment variables
    • There is also a ready-to-use GitHub Token
    • Full acces to the GitHub API via the Context (and more!)

    View Slide

  3. BUT
    This talk is not about GitHub Actions from the consumer side

    View Slide

  4. BUT
    This talk is about GitHub Actions from the developer side

    View Slide

  5. What?!
    Consumer: Developer:

    View Slide

  6. Build an Action
    Source

    View Slide

  7. Build an Action
    • “Native” with JavaScript or Docker container
    • JS is
    • faster
    • runs on all runners
    • not that flexible than a Docker container
    • Docker is
    • slower
    • runs only on Linux runners (shouldn’t be a problem, right?)
    • 100 percent flexible

    View Slide

  8. Build an Action – Where?
    • Own repository or inside your project repository in
    .github/actions/[nameOfAction]/
    • Own repository is reuseable

    View Slide

  9. Build an Action – Version!
    • commit -> author/[email protected]
    • tag -> author/[email protected]
    • branch -> author/[email protected]
    • Actions in your project repository don’t require this of course

    View Slide

  10. Build a Docker Action
    Source

    View Slide

  11. Build a Docker Action
    • Createa a Dockerfile
    • Requires a ENTRYPOINT
    • Create a Action Metadata file
    • (More about this later)
    • Write the Actions code in the entrypoint

    View Slide

  12. Build a JavaScript Action
    Source

    View Slide

  13. Build a JavaScript Action
    • Create a Action Metadata file
    • (More about this later)
    • Install Action toolskits
    • npm install @actions/core
    • npm install @actions/github
    • Write the Action code in a file called index.js

    View Slide

  14. The Action Metadata file
    Source

    View Slide

  15. The Action Metadata file
    • Describes the Action
    • inputs, outputs, runs (commands), ...

    View Slide

  16. The Action Metadata file - Input
    • The (maybe required) input for the Action to run

    View Slide

  17. The Action Metadata file - Input
    • The (maybe required) input for the Action to run

    View Slide

  18. The Action Metadata file - Output
    • The (maybe) output of the Action
    • An Action assembles an Android Project. The output is the apk/aab.
    • The output can be used with the expression syntax

    View Slide

  19. The Action Metadata file - Run
    • Run describes how the Action should be run. Docker or JavaScript
    • Docker: JS:
    Dockerfile or any public Docker image

    View Slide

  20. Want an example?
    https://github.com/Blackjacx/backlog-notifier

    View Slide