Github Action 同步仓库

引言

由于某些原因需要同步一个 Gitee 上的闭源仓库来学习里面的编程思想,但是每次看都需要 pull 一下仓库拉取最新代码比较麻烦,所以使用 Github Action 直接将代码拉到自己的私有仓库,方便自己学习。

正文

下面我们以 nginx/nginx 仓库为例。

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Sync Nginx Code 
on:
workflow_dispatch:
schedule:
- cron: '59 23 * * *'
jobs:
sync:
runs-on: ubuntu-18.04
if: github.repository == 'nginx/nginx'
timeout-minutes: 2
steps:
- name: Init Build Dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo -E rm -rf /etc/apt/sources.list.d
sudo -E apt-get update -y
sudo -E apt-get install -y build-essential git git-core curl wget jq
sudo -E apt-get clean -y
git config --global user.name 'GitHub Actions' && git config --global user.email '[email protected]'
# - name: Get Code from Private Repository
# run: |
# mkdir -p ~/.ssh
# echo -e "${{ secrets.KEY }}" > ~/.ssh/id_rsa
# chmod 600 ~/.ssh/id_rsa
# ssh-keyscan gitee.com > ~/.ssh/known_hosts
# git clone -b master [email protected]:nginx/nginx.git project
- name: Push to GitHub
run: |
echo -e "${{ secrets.GITHUBKEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com > ~/.ssh/known_hosts
cd project
git remote add github "${{ secrets.GITHUBREPO }}"
git push -u github master >/dev/null 2>&1
- name: Push to Gitee
run: |
echo -e "${{ secrets.GITEEKEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan gitee.com > ~/.ssh/known_hosts
cd project
git remote add gitee "${{ secrets.GITEEREPO }}"
git push -u gitee master >/dev/null 2>&1
- name: Delete Workflow Runs
uses: Mattraks/delete-workflow-runs@main
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 1
keep_minimum_runs: 0

Powered by Hexo and Hexo-theme-hiker

Copyright © 2018 - 2023 Leamx's Blog All Rights Reserved.

UV : | PV :