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

Introduction to GitHub Actions

Introduction to GitHub Actions

* What is different GitHub Flow and Git Flow?
* What is GitHub Actions?
* How to write the simple workflow?
* What's problem in GitHub Actions UI?
* What's problem with Secrets in GitHub Actions?
* How to write your first GitHub Actions and upload to the marketplace?
* What's a problem with environment variables in GitHub Actions?

Buy me a coffee: https://www.buymeacoffee.com/appleboy
Blog: https://blog.wu-boy.com
Twitter: https://twitter.com/appleboy
Facebook: https://www.facebook.com/appleboy46
Slideshare: https://www.slideshare.net/appleboy
GitHub: https://github.com/appleboy

Bo-Yi Wu

May 15, 2019
Tweet

More Decks by Bo-Yi Wu

Other Decks in Technology

Transcript

  1. Introduction to
    GitHub Actions
    2019/05/15
    Bo-Yi Wu
    https://github.com/appleboy

    View Slide

  2. About me
    • Software Engineer in Mediatek
    • Member of Drone CI/CD Platform
    • Member of Gitea Platform
    • Member of Gin Golang Framework
    • Teacher of Udemy Platform: Golang + Drone
    https://blog.wu-boy.com

    View Slide

  3. (JU)VC'MPX
    14
    Develop
    Git Push
    Git Tag
    Develop
    Git Push
    Git Tag
    Testing
    Deploy
    Deploy
    Deploy
    Production
    Staging
    Production
    Testing
    Deploy
    Staging

    View Slide

  4. GitHub Flow + Git Flow
    in opensource
    IUUQTHJUIVCDPNHPHJUFBHJUFB

    View Slide

  5. $*$%1MBUGPSN
    %SPOF 5SBWJT +FOLJOT
    (JU-BC $JSDMF $PEFTIJQ

    View Slide

  6. IUUQTHJUIVCDPNGFBUVSFTBDUJPOT
    #FUB

    View Slide

  7. IUUQTHJUIVCDPNNBSLFUQMBDF UZQFBDUJPOT
    .BSLFUQMBDF

    View Slide

  8. IUUQTEFWFMPQFSHJUIVCDPNBDUJPOT
    %FWFMPQFS(VJEF

    View Slide

  9. Container Based
    CI/CD Platform

    View Slide

  10. Current runtime resource
    • 1 virtual CPU
    • Up to 3.75GB of memory
    • 100GB of disk space

    View Slide

  11. 28Events

    View Slide

  12. Write Simple Workflow

    View Slide

  13. |-- hello-world (repository)
    | |__ .github
    | |__ main.workflow
    |

    View Slide

  14. workflow "Remote ssh commands" {
    on = "push"
    resolves = [
    "Remote ssh commands",
    ]
    }
    main.workflow

    View Slide

  15. action "Remote ssh commands" {
    uses = "appleboy/[email protected]"
    secrets = [
    "HOST",
    "PASSWORD",
    ]
    args = [
    "--user", "actions",
    "--script", "whoami",
    ]
    }
    main.workflow

    View Slide

  16. IUUQTHJUIVCDPNBQQMFCPZTTIBDUJPOBDUJPOT

    View Slide

  17. %PXOMPBEUIFEPDLFSJNBHFGPSDBDIJOH
    $BDIFMBZFS
    IUUQCJUMZEPDLFSDBDIFCVJME

    View Slide

  18. Scheduling a workflow
    ┌───────────── minute (0 - 59)
    │ ┌───────────── hour (0 - 23)
    │ │ ┌───────────── day of the month (1 - 31)
    │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
    │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
    │ │ │ │ │
    │ │ │ │ │
    │ │ │ │ │
    * * * * *
    workflow "New workflow" {
    on = "schedule(*/15 * * * *)"
    resolves = ["Hello World"]
    }

    View Slide

  19. What’s problem in UI?

    View Slide

  20. :PVDBO`UTFFUIFMPHJOQSPHSFTTKPC

    View Slide

  21. $BODFMMJOHXPSLqPX

    View Slide

  22. #VUZPVDBO`USFTUBSUUIFKPC
    http://www.thebrokeagent.com/wtf-listing-description-of-the-week/

    View Slide

  23. $ git reset —soft HEAD^
    $ git commit -a -m ‘foo’
    $ git push origin master -f
    3FTUBSUUIFKPC

    View Slide

  24. Secrets in Github Actions
    Setting -> Secrets in left sidebar

    View Slide

  25. View Slide

  26. action "Remote ssh commands" {
    uses = "appleboy/[email protected]"
    secrets = [
    "HOST",
    "PASSWORD",
    ]
    args = [
    "--user", "actions",
    "--script", "whoami",
    ]
    }
    main.workflow

    View Slide

  27. What’s problem in Secrets?

    View Slide

  28. Don’t support
    organization secrets
    duplicate of secrets in many repository of organization

    View Slide

  29. Don’t support
    thirty party
    secret service

    View Slide

  30. You need to write
    CLI flag in command
    drone-ssh -u foo -p foopass -s whoami
    drone-ssh -u bar -p barpass -s whoami

    View Slide

  31. main.workflow
    secrets = [
    "PASSWORD",
    ]
    args = [
    "--user", "actions",
    "--script", "whoami",
    ]
    secrets = [
    "PASSWORD",
    ]
    args = [
    "--user", "actions",
    "--script", "whoami",
    ]
    4FSWFS 4FSWFS
    EPDLFSSVOF1"44803%YYYBQQMFCPZESPOFTTI
    VBDUJPOTTXIPBNJ

    View Slide

  32. main.workflow
    secrets = [
    "PASSWORD01",
    ]
    args = [
    "-p", "$PASSWORD01",
    "--script", "whoami",
    ]
    secrets = [
    "PASSWORD02",
    ]
    args = [
    "-p", "$PASSWORD02",
    "--script", "whoami",
    ]
    4FSWFS 4FSWFS

    View Slide

  33. action "Publish" {
    needs = "Tag"
    uses = "actions/[email protected]"
    args = "publish --access public"
    secrets = ["NPM_AUTH_TOKEN"]
    }
    IUUQTHJUIVCDPNBDUJPOTOQN

    View Slide

  34. How to add multiple
    auth token
    of npm registry?

    View Slide

  35. kind: pipeline
    name: default
    steps:
    - name: build
    image: appleboy/drone-ssh
    environment:
    USERNAME:
    from_secret: username
    PASSWORD:
    from_secret: password

    View Slide

  36. Creating GitHub Actions

    View Slide

  37. |-- ssh-action (repository)
    | |__ .github
    | |__ main.workflow
    | |__ Dockerfile
    | |__ entrypoint.sh
    | |__ README.md
    | |__ LICENSE

    View Slide

  38. Support any language you want

    View Slide

  39. Dockerfile

    View Slide

  40. FROM appleboy/drone-ssh:1.5.0-linux-amd64
    # Github labels
    LABEL "com.github.actions.name"="SSH Commands"
    LABEL "com.github.actions.description"="some description"
    LABEL "com.github.actions.icon"="terminal"
    LABEL “com.github.actions.color"="gray-dark"
    LABEL "repository"="https://github.com/appleboy/ssh-action"
    LABEL "homepage"="https://github.com/appleboy"
    LABEL "maintainer"="Bo-Yi Wu "
    LABEL "version"="0.0.1"
    ADD entrypoint.sh /entrypoint.sh
    RUN chmod +x /entrypoint.sh
    ENTRYPOINT ["/entrypoint.sh"]

    View Slide

  41. entrypoint.sh

    View Slide

  42. #!/bin/sh
    set -eu
    export GITHUB="true"
    sh -c "/bin/drone-ssh $*"

    View Slide

  43. action "Tag Docker Image" {
    needs = ["build"]
    uses = "actions/docker/[email protected]"
    args = "tag hello:$GITHUB_SHA"
    }

    View Slide

  44. action "Tag Docker Image" {
    needs = ["build"]
    uses = "actions/docker/[email protected]"
    args = ["tag", "hello:$GITHUB_SHA"]
    }

    View Slide

  45. Environment variables

    View Slide

  46. action "Hello World" {
    uses = "./my-action"
    env = {
    FIRST_NAME = "Mona"
    MIDDLE_NAME = "Lisa"
    LAST_NAME = "Octocat"
    }
    }

    View Slide

  47. runtime environment

    View Slide

  48. GitHub Variable
    • GITHUB_WORKFLOW
    • GITHUB_ACTION
    • GITHUB_EVNETNAME
    • GITHUB_SHA
    • GITHUB_REF

    View Slide

  49. I don’t know how to
    get the author
    email, name or
    commit message
    3FTPMWFUIJTQSPCMFNVTJOH(JU)VC"1*SFRVFTU

    View Slide

  50. Publishing your action
    in the GitHub Marketplace

    View Slide

  51. FROM appleboy/drone-ssh:1.5.0-linux-amd64
    # Github labels
    LABEL "com.github.actions.name"="SSH Commands"
    LABEL "com.github.actions.description"="some description"
    LABEL "com.github.actions.icon"="terminal"
    LABEL “com.github.actions.color"="gray-dark"
    LABEL "repository"="https://github.com/appleboy/ssh-action"
    LABEL "homepage"="https://github.com/appleboy"
    LABEL "maintainer"="Bo-Yi Wu "
    LABEL "version"="0.0.1"
    ADD entrypoint.sh /entrypoint.sh
    RUN chmod +x /entrypoint.sh
    ENTRYPOINT ["/entrypoint.sh"]
    QMFBTFNBLFTVSFUIBUUIFSFJTOPQSPCMFNXJUI%PDLFSpMFJO-"#&-

    View Slide

  52. Create New Tag and
    Publish Release

    View Slide

  53. IUUQTHJUIVCDPNNBSLFUQMBDFBDUJPOTTTIDPNNBOET

    View Slide

  54. Some action I created
    • appleboy/ssh-action
    • appleboy/scp-action
    • appleboy/facebook-action
    • appleboy/telegram-action
    • appleboy/jenkins-action
    • appleboy/gitlab-ci-ation
    • appleboy/discord-action

    View Slide

  55. IUUQCJUMZHPMBOH

    View Slide

  56. IUUQCJUMZESPOF

    View Slide

  57. Thank You

    View Slide