GitHub使用方法

GitHub加速访问

1. 修改host文件达到加速目的

以下方法被写在一个python文件中,可以直接使用github faster执行python文件进行修改刷新

  1. 获取GitHub网站的最快地址,使用https://www.ipaddress.com/开获取GitHub的IP地址

  2. 修改hosts文件,Mac和Linux在/etc/hosts下,Windows在通常在C:\windows\System32\drivers\etc\hosts下,在结尾添加以下地址的IP

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    140.82.114.4 github.com
    199.232.69.194 github.global.ssl.fastly.net
    64.71.168.201 github.community
    199.232.68.133 avatars.githubusercontent.com
    199.232.68.133 avatars0.githubusercontent.com
    199.232.68.133 avatars1.githubusercontent.com
    199.232.68.133 avatars2.githubusercontent.com
    199.232.68.133 avatars3.githubusercontent.com
    199.232.68.133 avatars4.githubusercontent.com
    199.232.68.133 camo.githubusercontent.com
    199.232.68.133 cloud.githubusercontent.com
    199.232.68.133 githubusercontent.com
    199.232.96.133 user-images.githubusercontent.com
  3. 刷新hosts文件,Mac和Linux可以使用sudo killall -HUP mDNSResponder,Windows使用ipconfig /flushdns

参考文档:Mac 解决GitHub下载速度太慢问题

2. 使用加速镜像克隆

该方法只适用与对代码仓库进行克隆,不支持ssh方法

使用 github.com.cnpmjs.org 来替换原本的网站中的 github.com

git clone https://github.com/stolenzc/github_faster.git 替换为 git clone https://github.com.cnpmjs.org/stolenzc/github_faster.git

快速项目检索

检索方法:

1
2
3
4
5
6
7
in:name xxx # 按照项目名/仓库名搜索(大小写不敏感)
in:readme xxx # 按照README搜索(大小写不敏感)
in:description xxx # 按照description搜索(大小写不敏感)
stars:>xxx # stars数大于xxx
forks:>xxx # forks数大于xxx
language:xxx # 编程语言为xxx
pushed:>YYYY-MM-DD # 最新更新时间晚于YYYY-MM-DD

注意:多个条件之间可以使用空格隔开

Release发包

  1. 在项目的release窗格下,点击Draft a new release
  2. 填入Tag版本,描述之类的东西,然后点击或者将文件拖入到Attach binaries by dropping them here or selecting them.
  3. 点击Publish release即可完成发包,如果是测试包,可以勾选上this is a pre-release

GitHub Action

介绍

GitHub官方action仓库:Github Action官方市场,第三方仓库:wesome actions

使用action方式:使用git的指针概念,详情参考Github Docs

1
2
3
actions/setup-node@74bc508 # 指向一个 commit
actions/setup-node@v1.0 # 指向一个标签
actions/setup-node@master # 指向一个分支

配置

在项目根目录下的.github/workflows/下的yml文件

yml文件配置:

  1. name: workflow的名称,如果未设置默认为yml文件名

  2. on: 触发action的条件,可选为on.<push|pull_request>.<tags|branches>

  3. jobs: workflow的工作主体,表示每一项具体的工作,jobs下面通常需要写清楚job_id,可以自定义。如jobs:build。job_id下面为以下字段:

    1. name: 定义字段任务说明

    2. needs: 表示任务的依赖关系,表示运行该任务之前必须运行什么。

    3. runs-on: 运行任务需要的虚拟机环境,可选参数为:

      ubuntu-latestubuntu-18.04ubuntu-16.04

      windows-latestwindows-2019windows-2016

      macOS-latestmacOS-10.14

    4. steps: 每个job包含的步骤,可以配置为:

      name: 步骤名称

      uses: 使用的action

      with: github action的入参

      run: 执行的命令

      env: 设置为环境变量

实例

hexo项目编译并发送到阿里云ESC的指定目录

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
name: Hexo build and deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
# checkout到你的hexo代码分支
ref: master
# hexo需要加载内部子模块
submodules: true
- name: Install and Build
run: |
npm install
npm run build
- name: Deploy to aliyun server
uses: easingthemes/ssh-deploy@v2.0.7
env:
SSH_PRIVATE_KEY: ${{ secrets.ALIYUN_SERVER_ACCESS_TOKEN }}
ARGS: "-avz --delete"
SOURCE: "public/"
REMOTE_HOST: ${{ secrets.ALIYUN_SERVER_HOST }}
REMOTE_USER: "root"
TARGET: "/home/blog/"

该配置需要在secret里面配置阿里云的私钥,然后将阿里云的公钥添加到阿里云的~/.ssh/authorized_keys文件中添加阿里云中生成的公钥

该配置表示直接将hexo编译后的deploy下的文件拷贝到/blog/下,没有二级目录。

参考内容:阮一峰博客Github Action发布阿里云ECS