趣玩Github Action 发表于 2021-10-23 | 更新于 2024-11-24
| 总字数: 1.2k | 阅读时长: 5分钟 | 浏览量:
在 GitHub Actions 的仓库中自动化、自定义和执行软件开发工作流程。 您可以发现、创建和共享操作以执行您喜欢的任何作业(包括 CI/CD),并将操作合并到完全自定义的工作流程中。
Action 能干啥?都能干,前段时间还有人挖矿
下面所有的用户名和仓库用 laowang
和 zhangshan
代替
Actions secrets 一些不方便的隐私的东西可以放进去,然后用环境变量代替
https://github.com/laowang/zhangshan/settings/secrets/actions
1 2 3 4 5 DOCKERHUB_PASSWORD 123456 ${{ secrets.DOCKERHUB_PASSWORD }} DOCKERHUB_TOKEN 123456 ${{ secrets.DOCKERHUB_TOKEN }} DOCKERHUB_USERNAME laowang ${{ secrets.DOCKERHUB_USERNAME }} TOKEN_GITHUB 123456 ${{ secrets.TOKEN_GITHUB }}
Action.yml 这是一个简单的action文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 name: laowang de action on: push jobs: laowang_de_action: name: laowang de action runs-on: ubuntu-latest steps: - name: Private Actions Checkout uses: actions/checkout@v2.3.4 - name: Docker Setup QEMU uses: docker/setup-qemu-action@v1.2.0 run: echo "hello word"
on 1 2 3 4 5 6 7 8 9 on: push: branches: - main repository_dispatch: types: [laowang ] schedule: - cron: '0 0 * * MON'
那么 laowang
是怎么发出的呢?
1 2 3 4 5 6 7 8 9 10 11 12 13 jobs: laowang_fasong_tools: runs-on: ubuntu-latest steps: - name: laowang fasong tools uses: peter-evans/repository-dispatch@v1 with: token: ${{ secrets.TOKEN_GITHUB }} repository: ${{ secrets.DOCKERHUB_USERNAME }}/Code-Server-Update event-type: laowang client-payload: '{"ref": "${{ github.ref }} ", "sha": "${{ github.sha }} "}'
jobs 1 2 3 4 jobs: laowang_fasong_tools: runs-on: ubuntu-latest steps:
steps 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 jobs: laowang_fasong_tools: runs-on: ubuntu-latest steps: - name: Private Actions Checkout uses: actions/checkout@v2.3.4 - name: Docker Setup QEMU uses: docker/setup-qemu-action@v1.2.0 - name: Docker Setup Buildx uses: docker/setup-buildx-action@v1.6.0 - name: Docker Login uses: docker/login-action@v1.10.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker images uses: docker/build-push-action@v2.7.0 with: context: . platforms: linux/arm64,linux/amd64 push: true tags: | ${{ secrets.DOCKERHUB_USERNAME }}/code-server:init # 这里设置镜像的名称,并推送到hub file: .github/workflows/Dockerfile.init cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/code-server:init.cache cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/code-server:init.cache,mode=max
看了这么多,有点累了,上点才艺吧
img
越看越累😂,来把英雄联盟手游,打完了继续
对了,万一我设置了几个任务,但是他们是同步进行的,会报错,必须一个一个来怎么办?
needs 1 2 3 4 5 jobs: cha_hu_kou: needs: [zhangshan , zhangshan_cunweihui ] name: zhangshan_xian runs-on: ubuntu-latest
那如果我想运行自己的命令怎么办呢?
1 2 3 4 5 6 7 8 9 10 11 12 jobs: kaigong: needs: kaigong name: Docker Build PHP56 runs-on: ubuntu-latest steps: - name: dayin hello run: | echo "hello word" echo "word hello" # | 这样就能运行多条命令啦!
比较复杂 action.yml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 jobs: kaigong: needs: kaigong name: Docker Build PHP56 runs-on: ubuntu-latest steps: - name: Code Server Download run: | mkdir -p linux/arm64 linux/amd64 wget -O linux/amd64/code-server.rpm `curl https://api.github.com/repos/cdr/code-server/releases/latest | grep "browser_download_url" | cut -d '"' -f 4 | grep amd64.rpm` --no-cookie --no-check-certificate wget -O linux/arm64/code-server.rpm `curl https://api.github.com/repos/cdr/code-server/releases/latest | grep "browser_download_url" | cut -d '"' -f 4 | grep arm64.rpm` --no-cookie --no-check-certificate - name: Docker Login uses: docker/login-action@v1.10.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker images uses: docker/build-push-action@v2.7.0 with: context: . platforms: linux/arm64,linux/amd64 push: true tags: | laowang/code-server:latest cache-from: type=gha cache-to: type=gha,mode=max
dockerfile 1 2 3 4 5 6 7 8 9 10 FROM xrsec/php:latestLABEL maintainer="xrsec" LABEL mail="Jalapeno1868@outlook.com" ARG TARGETPLATFORM COPY ${TARGETPLATFORM} /code-server.rpm /www/ RUN rpm -ivh /www/code-server.rpm
还有一些复杂度挺高的,欢迎大家来我 github 参观 PHP_Docker
思考 怎么用 action
做到监控别的仓库更新自己也运行?除了发送信号还有别的方案吗?
XRSec has the right to modify and interpret this article. If you want to reprint or disseminate this article, you must ensure the integrity of this article, including all contents such as copyright notice. Without the permission of the author, the content of this article shall not be modified or increased or decreased arbitrarily, and it shall not be used for commercial purposes in any way