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 full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  5. What?!
    Consumer: Developer:

    View full-size slide

  6. Build an Action
    Source

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  10. Build a Docker Action
    Source

    View full-size 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 full-size slide

  12. Build a JavaScript Action
    Source

    View full-size 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 full-size slide

  14. The Action Metadata file
    Source

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size 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 full-size slide

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

    View full-size slide