在 GitHub Marketplace 中发布操作

Overview

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

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 上可看到
图片[1]-在 GitHub Marketplace 中发布操作-一一网
图片[2]-在 GitHub Marketplace 中发布操作-一一网

复制代码

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

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享