大佬教程收集整理的这篇文章主要介绍了使用@actions/core 或@actions/github 将 Github 操作写入 Node 中的存储库?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
学习 Github Actions 我终于能够从辅助存储库调用操作,例如:
.github/workflows/test.yml
name: Test Write Action
on:
push:
branches: [main]
jobs:
test_node_works:
runs-on: ubuntu-latest
name: Test if Node works
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
with:
repository: org/write-file-action
ref: main
token: ${{ secrets.ACTION_TOKEN }} # stored in GitHub secrets created from profile setTings
args: 'TESTinG'
- name: action step
uses: ./ # Uses an action in the root directory
ID: foo
with:
who-to-greet: 'Darth Vader'
- name: output time
run: |
echo "The details are ${{ steps.foo.outputs.repo }}"
echo "The time was ${{ steps.foo.outputs.time }}"
echo "time: ${{ steps.foo.outputs.time }}" >> ./foo.md
sHell: bash
并且行动是成功的。
action.yml:
## https://docs.github.com/en/actions/creaTing-actions/Metadata-Syntax-for-github-actions
name: 'Write file Action'
description: 'workflow tesTing'
inputs:
who-to-greet: # ID of input
description: 'Who to greet'
required: true
default: './'
outputs:
time: # ID of output
description: 'The time we greeted you'
repo:
description: 'user and repo'
runs:
using: 'node12'
main: 'dist/index.Js'
branding:
color: 'green'
icon: 'truck' ## https://docs.github.com/en/actions/creaTing-actions/Metadata-Syntax-for-github-actions#brandingicon
为 dist/index.Js
fs = require('fs')
const core = require('@actions/core')
const github = require('@actions/github')
try {
// `who-to-greet` input defined in action Metadata file
const nameToGreet = core.geTinput('who-to-greet')
console.log(`Hello ${nameToGreet}!`)
const time = new Date().totimestring()
core.setoutput('time',timE)
const repo = github.context.payload.repository.full_name
console.log(`full name: ${repo}!`)
core.setoutput('repo',repo)
// Get the JsON webhook payload for the event that triggered the workflow
const payload = JsON.Stringify(github.context.payload,undefined,2)
console.log(`The event payload: ${payloaD}`)
fs.writefileSync('payload.Json',payload) // Doesn't write to repo
} catch (error) {
core.setFailed(error.messagE)
}
package.Json:
{
"name": "wite-file-action","version": "1.0.0","description": "workflow tesTing","main": "dist/index.Js","scripts": {
"build": "ncc build ./index.Js"
},"dependencIEs": {
"@actions/core": "^1.4.0","@actions/github": "^5.0.0"
},"devDependencIEs": {
"@vercel/ncc": "^0.28.6","prettIEr": "^2.3.2"
}
}
但在当前工作流程中,action-playground
中没有创建任何内容。我能够写入存储库的唯一方法是从使用带有 github-api
的 API 的模块中,例如:
const GitHub = require('github-API')
const gh = new GitHub({
token: config.app.git_token,},githubUrl)
const repo = gh.getRepo(config.app.repoowner,config.app.repoName)
const branch = config.app.repoBranch
const path = 'README.md'
const content = '#Foo bar\nthis is foo bar'
const message = 'add foo bar to the readme'
const options = {}
repo.writefile(
branch,path,content,message,options
).then((r) => {
console.log(r)
})
并传入来自 github.context.payload
的存储库、组织或用户。我的最终目标是最终阅读以查看它是否存在,如果存在,则动态覆盖并写入 README.md 徽章:
`![${github.context.payload.workflow}](https://github.com/${github.context.payload.user}/${github.context.payload.repo}/actions/workflows/${github.context.payload.workflow}.yml/badge.svg?branch=main)`
第二个目标是创建一个 Markdown 文件(如 foo.md 或 payload.Json),但我无法从要写入的操作中运行 echo 命令我得到的 repo 是 Bash 而不是 Node。
有没有不使用 API 写入使用 Node 调用操作的存储库的方法?使用 run
时,这是否仅适用于 Bash:
- name: output
sHell: bash
run: |
echo "time: ${{ steps.foo.outputs.time }}" >> ./time.md
如果有怎么办?
研究:
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的使用@actions/core 或@actions/github 将 Github 操作写入 Node 中的存储库?全部内容,希望文章能够帮你解决使用@actions/core 或@actions/github 将 Github 操作写入 Node 中的存储库?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。