Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

GitHub Flow + Git Flow in opensource IUUQTHJUIVCDPNHPHJUFBHJUFB

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

IUUQTHJUIVCDPNGFBUVSFTBDUJPOT #FUB

Slide 7

Slide 7 text

IUUQTHJUIVCDPNNBSLFUQMBDF UZQFBDUJPOT .BSLFUQMBDF

Slide 8

Slide 8 text

IUUQTEFWFMPQFSHJUIVCDPNBDUJPOT %FWFMPQFS(VJEF

Slide 9

Slide 9 text

Container Based CI/CD Platform

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

28Events

Slide 12

Slide 12 text

Write Simple Workflow

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

IUUQTHJUIVCDPNBQQMFCPZTTIBDUJPOBDUJPOT

Slide 17

Slide 17 text

%PXOMPBEUIFEPDLFSJNBHFGPSDBDIJOH $BDIFMBZFS IUUQCJUMZEPDLFSDBDIFCVJME

Slide 18

Slide 18 text

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"] }

Slide 19

Slide 19 text

What’s problem in UI?

Slide 20

Slide 20 text

:PVDBO`UTFFUIFMPHJOQSPHSFTTKPC

Slide 21

Slide 21 text

$BODFMMJOHXPSLqPX

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Secrets in Github Actions Setting -> Secrets in left sidebar

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

What’s problem in Secrets?

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Don’t support thirty party secret service

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

action "Publish" { needs = "Tag" uses = "actions/npm@master" args = "publish --access public" secrets = ["NPM_AUTH_TOKEN"] } IUUQTHJUIVCDPNBDUJPOTOQN

Slide 34

Slide 34 text

How to add multiple auth token of npm registry?

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

Creating GitHub Actions

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Support any language you want

Slide 39

Slide 39 text

Dockerfile

Slide 40

Slide 40 text

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"]

Slide 41

Slide 41 text

entrypoint.sh

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

action "Tag Docker Image" { needs = ["build"] uses = "actions/docker/cli@master" args = "tag hello:$GITHUB_SHA" }

Slide 44

Slide 44 text

action "Tag Docker Image" { needs = ["build"] uses = "actions/docker/cli@master" args = ["tag", "hello:$GITHUB_SHA"] }

Slide 45

Slide 45 text

Environment variables

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

runtime environment

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

Publishing your action in the GitHub Marketplace

Slide 51

Slide 51 text

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-"#&-

Slide 52

Slide 52 text

Create New Tag and Publish Release

Slide 53

Slide 53 text

IUUQTHJUIVCDPNNBSLFUQMBDFBDUJPOTTTIDPNNBOET

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

IUUQCJUMZHPMBOH

Slide 56

Slide 56 text

IUUQCJUMZESPOF

Slide 57

Slide 57 text

Thank You