我正在使用该github-script操作来使用一些 javascript 来完成工作流程中的某些任务。
workflow_dispatch例如,如果我使用带有触发器的工作流程,我可以通过 获取其输入context.payload.inputs。
我正在利用可重用的工作流程,因此我有一个带有workflow_call触发器的工作流程,然后是另一个通过 调用该工作流程的工作流程jobs.<job>.uses。
在工作流文件中使用模板时,workflow_dispatch输入的引用方式与 a 类似${{ github.event.inputs.<input_name> }},但要将输入引用到 a workflow_call,我们只需使用${{ inputs.<input_name> }}. 在对值进行模板化时一切都很好,没有问题,但我想知道如何inputs从 JS 中直接获取该上下文。我似乎找不到它,也找不到任何例子。
以下是一些要演示的片段:
workflow_dispatch例子---
name: scripty
on:
workflow_dispatch:
inputs:
dummy:
required: false
description: dummy
jobs:
scripty:
runs-on: ubuntu-latest
steps:
- name: script
id: script
uses: actions/github-script@v5
with:
script: |
var dummy = context.payload.inputs.dummy
return {
context: context,
github: …Run Code Online (Sandbox Code Playgroud) 我希望能够在预定时间更新 GitHub 页面。我想到的唯一方法是在计划的时间重命名更新的文件以建立索引并删除以前的索引。有没有办法删除或重命名文件?
我想配置 GitHub Actions 工作流程,以便它在分支推送上运行,但不在标签推送上运行。我认为这会起作用:
on:
push:
tags-ignore: ['**']
Run Code Online (Sandbox Code Playgroud)
但当我推送分支时,工作流程也无法运行。有没有办法配置它,使其在分支推送上运行,而不是在标签推送上运行?
google-github-actions/auth@v0我正在尝试通过 github 使用和在 GAR(Google Artifact Registry)上发布 npm 包google-artifactregistry-auth
对于从 github 到 google 的身份验证,我使用联合工作负载身份执行以下操作:
export PROJECT_ID="my-project-id"
gcloud iam service-accounts create "gh-deploy-service-account" --project "${PROJECT_ID}"
gcloud iam workload-identity-pools create "github-pool" --project="${PROJECT_ID}" --location="global" --display-name="Github pool"
gcloud iam workload-identity-pools describe github-pool" --project="${PROJECT_ID}" --location="global" --format="value(name)"
export WORKLOAD_IDENTITY_POOL_ID=projects/my-custom-id-number/locations/global/workloadIdentityPools/github-pool
gcloud iam workload-identity-pools providers create-oidc "github-provider" \
--project="${PROJECT_ID}" \
--location="global" \
--workload-identity-pool="github-pool" \
--display-name="Github provider" \
--attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \
--issuer-uri="https://token.actions.githubusercontent.com"
export REPO="@example/my-package"
gcloud iam service-accounts add-iam-policy-binding "gh-deploy-service-account@${PROJECT_ID}.iam.gserviceaccount.com" \
--project="${PROJECT_ID}" \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/${REPO}"
Run Code Online (Sandbox Code Playgroud)
然后我在谷歌上创建了我的工件存储库:
gcloud artifacts repositories create …Run Code Online (Sandbox Code Playgroud) github gcloud github-actions google-artifact-registry workload-identity
这是我到目前为止的工作流程,github告诉我第8行有错误,但我找不到它。
name: restartServer
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- run: >
curl --location --request POST 'https://panel.discordbothosting.com/api/client/servers/fd21d417/power' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer APIKEY' \
--data-raw '{
"signal": "restart"
}'
Run Code Online (Sandbox Code Playgroud) 根据此处找到的文档,我尝试设置 GitHub Action 环境变量,但注意到环境变量似乎没有保存。这是否已被弃用,或者文档/我的实现是否不正确?
- name: Get Gradle VersionName
working-directory : ${{ github.workspace }}/app
run : |
echo "Get Gradle VersionName"
echo "action_state=yellow" >> $GITHUB_ENV
echo "${{ env.action_state }}"
grep 'versionName' build.gradle | awk '{print $2}'
Run Code Online (Sandbox Code Playgroud)
我已使用此处提到[skip ci]的命令跳过 GitHub 操作中的工作流程运行,在使用 PAT 在 CI aciton 中构建图像后,我正在执行自动提交,效果非常好!
但由于提交注释包含该[skip ci]命令,并且在此之后如果我创建新的标签版本,则不会触发 CI 工作流程,因为[skip ci].
有什么方法可以排除[skip ci]for 标签推送事件并仅将其保留在运行 ci 操作的分支之一吗?
GitHub 操作中的自动提交:
on: push
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: build and push image
- name: update image tag
- name: Commit changes
run: |
git config --global user.name 'abc'
git config --global user.email 'xyz@users.noreply.github.com'
git remote add origin https://github.com/${{ github.repository }}
git config --global push.default current
git remote set-url origin …Run Code Online (Sandbox Code Playgroud) 我想在满足以下约束时触发操作。
pr 合并到主分支并且 pr 包含 label == 'site'。
这就是我想到的,创建 pr 时运行的问题。
当我将它合并到 main 时什么也没有发生。
我究竟做错了什么?
name: Build and push site
on:
pull_request:
branches: [main]
types: [labeled, closed]
jobs:
build-push-site:
if: github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'site')
uses: avifatal/nx-tokenct/.github/workflows/build-push.yml@main
with:
...
Run Code Online (Sandbox Code Playgroud)
(受到拉取请求具有特定标签时运行 Github 操作的启发)
谢谢
我正在尝试建立从 GitHub 操作到 GAE 的部署管道。
我首先遵循此文档https://github.com/google-github-actions/auth#setup,使用设置工作负载身份联合方法。
看起来一切似乎都工作顺利,直到我使用gcloud app deploy或gcloud services list --enabled任何需要身份验证的命令的部分(在“构建”步骤中)。
.github\workflows\app-engine.yml
name: Build using Cloud Build
on:
push:
branches:
- main
env:
PROJECT_ID: testinfra3
SERVICE_NAME: default
jobs:
setup-build-deploy:
name: Setup, Build, and Deploy
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
service_account: 'my-service-account@my-project.iam.gserviceaccount.com'
- name: 'Set up Cloud SDK'
uses: google-github-actions/setup-gcloud@v0
- …Run Code Online (Sandbox Code Playgroud) google-app-engine continuous-deployment google-cloud-platform github-actions
github-actions ×10
github ×5
gcloud ×1
github-api ×1
github-pages ×1
node.js ×1
pull-request ×1
yaml ×1