目 录CONTENT

文章目录

收集各种用法的 Github Action

16Reverie
2025-04-15 / 0 评论 / 1 点赞 / 63 阅读 / 0 字

语言类

执行 JavaScript 代码

名称及示例action/github-script

    - name: Install axios
      run: npm install axios@1.8.4
    - name: Check Detail Data
      id: handel-json
      uses: actions/github-script@v7
      with:
        result-encoding: string
        script: |
          const axios = require('axios');
          const response = await axios.get(url, { timeout: 5000 });
          ...data...

仓库地址:https://github.com/actions/github-script

安装 Python 运行环境

名称及示例:actions/setup-python

    - uses: actions/setup-python@v5
      with:
        python-version: '3.13' 
    - run: python my_script.py  

仓库地址:https://github.com/actions/setup-python

安装 Node.js

名称及示例:setup-node

     - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'

      - name: Install dependencies
        run: npm install

      - name: Run Node.js script
        run: node index.js    

仓库地址:https://github.com/actions/setup-node

常用工具类

仓库提交

名称及示例:EndBug/add-and-commit@v9

    - name: Git Add and Commit
      uses: EndBug/add-and-commit@v9
      with:
        message: 'chore(data): update neodb data'
        committer_name: 'github-actions[bot]'
        committer_email: 'github-actions[bot]@users.noreply.github.com'
        add: |
          './data'

触发仓库调度事件

名称及示例:peter-evans/repository-dispatch

      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.PAT }}
          repository: username/my-repo
          event-type: my-event

仓库地址:https://github.com/peter-evans/repository-dispatch

rsync 文件同步

名称及示例:burnett01/rsync-deployments

      - name: rsync deployments
        uses: burnett01/rsync-deployments@7.0.2
        with:
          switches: -avzr --delete
          path: public/
          remote_path: 目标主机同步目录
          remote_host: 目标主机 IP 地址
          remote_port: 目标主机 SSH 端口
          remote_user: 目标主机用户名
          remote_key: 目标主机 SSH KEY

仓库地址:https://github.com/Burnett01/rsync-deployments

SSH 操作

名称及示例:appleboy/ssh-action

      - name: executing remote ssh commands using password
        uses: appleboy/ssh-action@v1
        with:
          host: SSH host
          username: SSH 用户名
          password: SSH 密码
          port: SSH 端口
          script: |
            cd /root
            rm * -rf

仓库链接:https://github.com/appleboy/ssh-action

其他

HUGO 安装

名称及示例:peaceiris/actions-hugo

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: '0.145.0'
          extended: true

      - name: Build 
        run: hugo --minify # 执行构建命令

仓库地址:https://github.com/peaceiris/actions-hugo

1

评论区