GitHub Actions 工作流程
自動化部署到騰訊雲 COS
獲取 API 密鑰
騰訊雲控制檯 - 訪問管理 - 創建 API 密鑰或者子用戶
- 子用戶權限策略 -
QcloudCOSDataFullControl - 獲取
SecretId和SecretKey
獲取 COS 桶信息
騰訊雲控制檯 - 對象存儲 - 存儲桶 - 基本配置
- 空間名(Bucket) - xxx-xxxxxx
- 所屬地域(Region) - ap-shanghai
配置 Secrets
GitHub 倉庫 - Settings - Secrets
添加上文創建的 SecretId SecretKey Bucket Region
創建workflow
GitHub 倉庫 - Actions - Set up a workflow yourself
- 創建
sync.yml - 提交sync.yml後,檢測到 push 後將會自動 Upload 到騰訊雲 COS
yaml
name: sync to cos
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install coscmd
run: sudo pip install coscmd
- name: Configure coscmd
env:
SECRET_ID: ${{ secrets.SecretId }}
SECRET_KEY: ${{ secrets.SecretKey }}
BUCKET: ${{ secrets.Bucket }}
REGION: ${{ secrets.Region }}
run: coscmd config -a $SECRET_ID -s $SECRET_KEY -b $BUCKET -r $REGION
- name: Upload
run: coscmd upload -rfs --delete ./ / --ignore "./.git/*"Fork 倉庫後定時拉取原項目 Commits
yaml
name: Merge-upstream
on:
push:
branches:
- master
schedule:
- cron: 40 16 * * *
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
with:
ref: master
fetch-depth: 0
lfs: true
- name: Set git identity
run: |
git config --global user.email "xxx@xxx.com"
git config --global user.name "xxxxx"
- name: Load upstream commits
run: git pull https://github.com/xxxxxx/xxxxxx.git --no-edit --strategy-option ours
- name: Push Commits
env:
DOWNSTREAM_BRANCH: master
run: git push origin $DOWNSTREAM_BRANCH自動同步 fork 上游倉庫
修改以下git config信息和upstream上游倉庫,並設置cron定時同步或本人star倉庫觸發同步.
yaml
name: Merge upstream branches
on:
push:
schedule:
- cron: '0 18 * * *'
watch:
types: [started]
jobs:
merge:
runs-on: ubuntu-latest
if: github.event.repository.owner.id == github.event.sender.id
steps:
- uses: actions/checkout@v2.3.5
- name: Merge upstream
run: |
git config --global user.name 'name'
git config --global user.email 'name@email.com'
git pull --unshallow
git remote add upstream https://github.com/xxxxx/xxxxx.git
git fetch upstream
git checkout main
git merge --no-edit upstream/main
git push origin main
git fetch upstream --tags
git push --tags自動構建和上傳鏡像
yaml
name: Build and push Docker images for ubuntu
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build and push Docker images
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: stilleshan/xxxxx
tags: latest
path: xxxx/自動合併拉取請求
將其中的 imgbot[bot] 修改成需要自動合併的作者
yaml
name: Merge pull request
on:
pull_request:
types:
- opened
- ready_for_review
pull_request_review:
types:
- submitted
status: {}
jobs:
imgbot:
name: Merge pull request
runs-on: ubuntu-latest
permissions: write-all
if: ${{ github.actor == 'imgbot[bot]' && github.event_name == 'pull_request'}}
steps:
- name: Enable auto-merge for imgbot PRs
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}