GitHub Actions 学习笔记
2020-02-03
- 使用 RMarkdown 的
child
参数,进行文档拼接。 - 这样拼接以后的笔记方便复习。
- 相关问题提交到 Issue
1 安装
GitHub Learning Lab will create a repository named hello-github-actions on your GitHub account. You cannot register for a course until you have installed the app.
安装 App
Need tighter permissions? You can also install the app each time you register for a new course/repository. Limit GitHub Learning Lab to Course Repositories
完成后,就开始了,需要一个项目learn_make
授权 app。
Hello, GitHub Actions! Your “Hello, World” for GitHub Actions GitHub Actions Workflows Hello World JiaxiangBU/hello-github-actions
开始学习 GitHub Actions。
2 Add a Dockerfile
Start your action by creating a Dockerfile
- 按照第一个 issue 1 的要求完成作业
要求见 https://github.com/JiaxiangBU/hello-github-actions/issues/1
$ git clone https://github.com/JiaxiangBU/hello-github-actions.git
Cloning into 'hello-github-actions'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
$ git status | clip
On branch first-branch
Untracked files:
(use "git add <file>..." to include in what will be committed)
action-a/
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git commit -m 'add Dockerfile'
[first-branch 730362e] add Dockerfile
1 file changed, 14 insertions(+)
create mode 100644 action-a/Dockerfile
$ git push --set-upstream origin first-branch
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 580 bytes | 580.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'first-branch' on GitHub by visiting:
remote: https://github.com/JiaxiangBU/hello-github-actions/pull/new/first-branch
remote:
To https://github.com/JiaxiangBU/hello-github-actions.git
* [new branch] first-branch -> first-branch
Branch 'first-branch' set up to track remote branch 'first-branch' from 'origin'.
然后操作 pull request 完成。
3 R project 进行
方便进行 IDE 编辑。
4 Add an entrypoint script
参考 https://github.com/JiaxiangBU/hello-github-actions/pull/2#issuecomment-581152177
$ git add .
$ git commit -m 'add shell script'
[first-branch 15ef10d] add shell script
1 file changed, 3 insertions(+)
create mode 100644 entrypoint.sh
$ git push
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 934 bytes | 467.00 KiB/s, done.
Total 7 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/JiaxiangBU/hello-github-actions.git
730362e..15ef10d first-branch -> first-branch
5 Start your workflow file
参考 https://github.com/JiaxiangBU/hello-github-actions/pull/2#issuecomment-581153242
$ git add .
$ git commit -m 'add workflow yaml'
[first-branch c221d61] add workflow yaml
1 file changed, 2 insertions(+)
create mode 100644 .github/workflows/main.yml
$ git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 418 bytes | 418.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/JiaxiangBU/hello-github-actions.git
1b99510..c221d61 first-branch -> first-branch
6 Run an action from your workflow file
name: A workflow for my Hello World file
gives your workflow a name. This name appears on any pull request or in the Actions tab. The name is especially useful when there are multiple workflows in your repository.on: push
indicates that your workflow will execute anytime code is pushed to your repository, using thepush
event.
jobs:
build:
name: Hello world action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./action-a
env:
MY_NAME: "Mona"
这里找到了定义的MY_NAME: "Mona"
。
$ git add .
$ git commit -m 'add job'
[first-branch bbe5fbd] add job
1 file changed, 10 insertions(+)
$ git push
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 511 bytes | 255.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/JiaxiangBU/hello-github-actions.git
c221d61..bbe5fbd first-branch -> first-branch
7 Seeing your Action in action
uses: actions/checkout@v1
uses a community action calledcheckout
to allow the workflow to access the contents of the repositoryuses: ./action-a
provides the relative path the action we’ve created in theaction-a
directory of the repositoryenv
: is used to specify the environment variables that will be available to your action in the runtime environment. In this case, the environment variable isMY_NAME
, and it is currently initialized to"Mona"
.
所以这个项目必须要公开的,因为 workflow 要访问这个项目。
This action will run any time a new commit is created or pushed to the remote repository. Since you just created a commit, the workflow should have been triggered. This might take a few minutes since it’s the first time running in this repository.
每次 push 都会调用这个 GitHub Actions。 并且第一次会比较花时间。
8 Trigger the workflow
https://github.com/JiaxiangBU/hello-github-actions/actions 查看效果。
9 可以创建 badge
![A workflow for my Hello World file](https://github.com/JiaxiangBU/hello-github-actions/workflows/A%20workflow%20for%20my%20Hello%20World%20file/badge.svg)
10 Incorporate the workflow
https://github.com/JiaxiangBU/hello-github-actions/pull/2#pullrequestreview-351953751
见 https://github.com/JiaxiangBU/hello-github-actions/runs/421904399?check_suite_focus=true#step:3:58
这是生成的Hello world my name is Mona
As a final step, merge this pull request so the action will be a part of the master branch. - Your merge should trigger your action again, check it out in the Actions tab. https://github.com/JiaxiangBU/hello-github-actions/issues/3
见 https://github.com/JiaxiangBU/hello-github-actions/runs/421913765?check_suite_focus=true