美文网首页
在 GitHub Marketplace 中发布操作

在 GitHub Marketplace 中发布操作

作者: 仇志飞 | 来源:发表于2021-07-09 14:22 被阅读0次

    Overview

    创建自己的操作, 发布到 GitHub 社区 marketplace

    imgs20210708183340.png

    Create Marketplace apps

    创建项目 iOS-helper-action

    mkdir iOS-helper-action
    

    创建 action metadata file

    action.yml
    
    name: 'iOS Helper Action'
    description: 'Tool for iOS developers to automate tedious tasks like swiftlint, pod-lib-lint, install, run, test.'
    inputs:
      action:  # action
        description: 'automate tedious tasks'
        required: true
    runs:
      using: "node12"
      main: "dist/index.js"
    

    提交、标记和推送操作到 GitHub

    编写 index.js

    echo 'node_modules/' > .gitignore
    
    npm install @actions/core
    npm install @actions/exec
    
    vi index.js
    

    index.js 只负责接收参数, 并转发给 build.sh

    const core = require("@actions/core");
    const exec = require("@actions/exec");
    
    async function run() {
      try {
        // Validate action
        if (
          !core.getInput("action")
        ) {
          throw new Error("action missing or in the wrong format.");
        }
    
        const action = core.getInput("action");
        console.log(`Action: ${action}`);
        // Execute build.sh
        await exec.exec(`bash ${__dirname}/../build.sh ${action}`);
      } catch (error) {
        core.setFailed(error.message);
      }
    }
    
    run();
    

    build.sh 中完成具体的操作

    vi build.sh
    
    #!/bin/bash
    
    if !(which xchelper >/dev/null); then
      echo "Installing xchelper"
      sh -c "$(curl -fsSL https://raw.githubusercontent.com/BlueIntent/xchelper/main/scripts/install.sh)"
      echo "Done!"
    fi
    
    xchelper $1
    

    编译 index.js

    npm i -g @vercel/ncc --verbose
    ncc build index.js --license licenses.txt
    

    添加 tag, 并提交

    git tag v0.0.1
    git push --tags
    

    测试

    提交后, 修改 workfile 引用, 即可

    - uses: BlueIntent/iOS-helper-action@v0.0.1
      with:
        action: 'swiftlint'
    

    发布

    测试通过后, 可发布到 Marketplace.
    在自己 github 上可看到


    imgs20210708181732.png imgs20210708182602.png

    iOS Helper Action 发布成功

    Usage

    - name: swiftlint
      uses: BlueIntent/iOS-helper-action@v0.0.1
      with:
        action: 'swiftlint'
    

    可查看示例 iOS-test-with-xchelper-action.yml, 直接编辑提PR, 可直接测试.

    References

    Homepage

    相关文章

      网友评论

          本文标题:在 GitHub Marketplace 中发布操作

          本文链接:https://www.haomeiwen.com/subject/cusfpltx.html