KEMBAR78
Introduction to GitHub Actions | PDF
Introduction to
GitHub Actions2019/05/15
Bo-Yi Wu
https://github.com/appleboy
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
GitHub Flow
14	
Develop
Git Push
Git Tag
Develop
Git Push
Git Tag
Testing
Deploy
Deploy
Deploy
Production
Staging
Production
Testing
Deploy
Staging
GitHub Flow + Git Flow
in opensource
https://github.com/go-gitea/gitea
CI/CD Platform
Drone Travis Jenkins
GitLab Circle Codeship
https://github.com/features/actions
Beta
https://github.com/marketplace?type=actions
Marketplace
https://developer.github.com/actions/
Developer Guide
Container Based
CI/CD Platform
Current runtime resource
• 1 virtual CPU
• Up to 3.75GB of memory
• 100GB of disk space
28Events
Write Simple Workflow
|-- hello-world (repository)
| |__ .github
| |__ main.workflow
|
workflow "Remote ssh commands" {
on = "push"
resolves = [
"Remote ssh commands",
]
}
main.workflow
action "Remote ssh commands" {
uses = "appleboy/ssh-action@master"
secrets = [
"HOST",
"PASSWORD",
]
args = [
"--user", "actions",
"--script", "whoami",
]
}
main.workflow
https://github.com/appleboy/ssh-action/actions
Download the docker image for caching
Cache layer
http://bit.ly/docker-cache-build
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"]
}
What’s problem in UI?
You can’t see the log in progress job
Cancelling workflow
But you can’t restart the job
http://www.thebrokeagent.com/wtf-listing-description-of-the-week/
$ git reset —soft HEAD^
$ git commit -a -m ‘foo’
$ git push origin master -f
Restart the job
Secrets in Github Actions
Setting -> Secrets in left sidebar
action "Remote ssh commands" {
uses = "appleboy/ssh-action@master"
secrets = [
"HOST",
"PASSWORD",
]
args = [
"--user", "actions",
"--script", "whoami",
]
}
main.workflow
What’s problem in Secrets?
Don’t support
organization secrets
duplicate of secrets in many repository of organization
Don’t support
thirty party
secret service
You need to write
CLI flag in command
drone-ssh -u foo -p foopass -s whoami
drone-ssh -u bar -p barpass -s whoami
main.workflow
secrets = [
"PASSWORD",
]
args = [
"--user", "actions",
"--script", "whoami",
]
secrets = [
"PASSWORD",
]
args = [
"--user", "actions",
"--script", "whoami",
]
Server 01 Server 02
docker run -e PASSWORD=xxx appleboy/drone-ssh
-u actions -s whoami
main.workflow
secrets = [
"PASSWORD01",
]
args = [
"-p", "$PASSWORD01",
"--script", "whoami",
]
secrets = [
"PASSWORD02",
]
args = [
"-p", "$PASSWORD02",
"--script", "whoami",
]
Server 01 Server 02
action "Publish" {
needs = "Tag"
uses = "actions/npm@master"
args = "publish --access public"
secrets = ["NPM_AUTH_TOKEN"]
}
https://github.com/actions/npm
How to add multiple
auth token
of npm registry?
kind: pipeline
name: default
steps:
- name: build
image: appleboy/drone-ssh
environment:
USERNAME:
from_secret: username
PASSWORD:
from_secret: password
Creating GitHub Actions
|-- ssh-action (repository)
| |__ .github
| |__ main.workflow
| |__ Dockerfile
| |__ entrypoint.sh
| |__ README.md
| |__ LICENSE
Support any language you want
Dockerfile
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 <appleboy.tw@gmail.com>"
LABEL "version"="0.0.1"
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/sh
set -eu
export GITHUB="true"
sh -c "/bin/drone-ssh $*"
action "Tag Docker Image" {
needs = ["build"]
uses = "actions/docker/cli@master"
args = "tag hello:$GITHUB_SHA"
}
action "Tag Docker Image" {
needs = ["build"]
uses = "actions/docker/cli@master"
args = ["tag", "hello:$GITHUB_SHA"]
}
Environment variables
action "Hello World" {
uses = "./my-action"
env = {
FIRST_NAME = "Mona"
MIDDLE_NAME = "Lisa"
LAST_NAME = "Octocat"
}
}
runtime environment
GitHub Variable
• GITHUB_WORKFLOW
• GITHUB_ACTION
• GITHUB_EVNETNAME
• GITHUB_SHA
• GITHUB_REF
I don’t know how to
get the author
email, name or
commit message
Resolve this problem using GitHub API request?
Publishing your action
in the GitHub Marketplace
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 <appleboy.tw@gmail.com>"
LABEL "version"="0.0.1"
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
please make sure that there is no problem with Dockerfile in LABEL
Create New Tag and
Publish Release
https://github.com/marketplace/actions/ssh-commands
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
http://bit.ly/golang-2019
http://bit.ly/drone-2019
Thank You

Introduction to GitHub Actions