惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
D
Docker
S
SegmentFault 最新的问题
博客园 - 聂微东
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
L
LangChain Blog
Vercel News
Vercel News
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
T
Threatpost
Scott Helme
Scott Helme
T
Tailwind CSS Blog
Latest news
Latest news
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
The Register - Security
The Register - Security
罗磊的独立博客
P
Proofpoint News Feed
腾讯CDC
S
Schneier on Security
雷峰网
雷峰网
A
About on SuperTechFans
T
Tenable Blog
F
Full Disclosure
Cyberwarzone
Cyberwarzone
博客园_首页
有赞技术团队
有赞技术团队
K
Kaspersky official blog

Yorksite

Plog004:好吃好吃 · Plog Plog003:Until Then · Plog Plog002:春天花会开 · Plog Plog001:让人疲惫的AI与在战锤世界中仰泳,赞美欧姆尼赛亚? · Plog rhaeTree:一个基于 Rust 的进化树可视化编辑工具 · Articles 我的键盘快捷键们 · Articles 迟到的2025年度数码产品总结 · Articles 关于我和这个博客 · Info 买了一只十多年前的老 Pebble · Articles 盘点一下今年让我上头的那些游戏 · Articles 【吃了啥】新利查西菜馆 · Articles 根据Zotero数据库追踪新发表文献 · Articles 解决远程服务器上Singularity联网问题 · Articles 又是一个Mac软件列表 · Articles Vita3K存档转移到PSV实机 · Articles SnapGene创建多外显子基因结构 · Articles Rstudio也能用GitHub Copilot了 · Articles 双十一买了啥 · Articles 文献一团乱麻?试试PARA管理方法 · Articles 点名的风还是吹到了Blog · Articles 从Raindrop迁移到了Anybox · Articles 数据可视化——基本图形元素及其应用 · Articles 单变量异常值检测方法 复现一张相关性图 · Articles 【读文献】单细胞分析最佳实践 · Articles Docker 打包 Shiny App · Articles Hello, again · Articles 1 dataset 100 visualizations 中有意思的可视化 · Articles 论文可视化配色简易指南 Karabiner 助力,让你的键盘操作快人一步 · Articles 我的植物组学数据库合集 Ver.20220528 · Articles 利用 n8n 打造飞书 RSS 推送机器人 · Articles 「#」的前世今生 克服低效率恐惧,回归健康生活
部署预印本追踪 TRxiv 到 Github Action · Articles
2023-03-25 · via Yorksite

Published Mar 24, 2023

3 minutes read

将JS写的抓取 Altmetric 热门预印本,与 bioRxiv API 结合后储存在 csv 文件中的过程,部署在 Github Action 中。官方文档写的顺序都有点混乱,网上找到的教程又经常都比较老了,因此自己记录一个。

新建Github仓库

新建一个public仓库,名叫TRxiv,并将远程仓库git clone到本地。

git clone git@github.com:Yorks0n/TRxiv.git
 
cd TRxiv
 

创建一个动作元数据文件

要让仓库里能被以Action的形式直接调用,需要在根目录中创建一个action.yml配置文件,可以在这个文件中指定Action的输入和输出,调用的参数及运行环境

# action.yml
name: 'trxiv'
description: 'Tracking popular bioRxiv and medRxiv preprints'
 
runs:
  using: 'node16'
  main: 'dist/index.js'

准备运行的代码

手动将写好的JS脚本拷贝进来,完整代码在此 Yorkson/TRxiv

# 在这里初始化一下npm
npm init -y

准备一个.gitignore文件,防止在推送的时候把不必要的文件放到储存库,可以用下面这个工具,或者自己写一下,比如这里就可能有node_modules

https://www.toptal.com/developers/gitignore

文件推送到远程仓库

然后push到远程仓库

git add .
git commit -m "Initialize"
git push

打包软件

因为前面把node_modules 从上传的文件列表中忽略了,但脚本index.js内有些依赖的包,所以最好把软件和依赖打包在一起,官方推荐用ncc

npm install @vercel/ncc

然后对index.js 进行打包

ncc build index.js -o dist

打包产物会存放于dist/index.js

创建工作流

在本地创建.github/workflows/main.yml,这个文件实际确定了 Github Action 的行为,此yml格式文件一定要注意正确的缩进。

配置文件内容:

# main.yml
## 动作的名称
name: 'TRxiv update'
 
# 触发条件
## 条件1,代码push进仓库
## 条件2,定时任务,在UTC 10和22点,即北京时间18点和6点运行
on:
  push:
  schedule:
    - cron: '0 10,22 * * *'
 
# jobs 定义了要执行的一系列任务 
 
jobs:
  ## 这个job的名称
  TRxiv_update_job:
    ## runs-on 内置运行任务的server类型
    runs-on: ubuntu-latest
    name: Update the csv file
    steps: 
      ## 必须有这一步,让运行的文件夹成为一个git repo
      - uses: actions/checkout@v3
      ## 运行脚本,指向我们的repo
      - name: 'run script'
        uses: Yorks0n/TRxiv@main
      ## 运行完后,把运行产生在本地的data.csv更新回仓库中
      - name: Commit files
        run: |
         git config --local user.email "github email adress"
         git config --local user.name "github user name"
         git pull
         git add README.md
         git add data.csv
         git commit -m "update data.csv"
        shell: bash
      ## 使用秘钥确认具有上传权限,同时以秘钥方式提交不会触发push action,避免陷入loop
      - name: Push changes
        uses:  ad-m/github-push-action@master
        with:
         github_token: ${{ secrets.MY_GIT_TOKEN }}
         branch: main

再次将文件推送到远程仓库

git add .
git commit -m "Update Workflow"
git push

后续更新

每次想更新修改前,先在目录中把最新版的环境拉下来

git pull

修改过脚本后,要重新打包用到的代码ncc build index.js --license licenses.txt

然后再提交回仓库

参考

How to Build Your First JavaScript GitHub Action

如何使用 Github Actions 自动抓取每日必应壁纸?

Permission denied to github-actions[bot]

Creating a JavaScript action - GitHub Docs