Skip to content
Go back

github action 相关信息

Updated:
Edit page

ERR_MSG=$(cat err.log)
ERR_MSG="${ERR_MSG//'%'/'%25'}"
ERR_MSG="${ERR_MSG//$'\n'/'%0A'}"
ERR_MSG="${ERR_MSG//$'\r'/'%0D'}"
echo "::error title=err::$ERR_MSG"

- name: Failed
if: ${{ failure() }}
run: |
  if grep -q 'errorMessage' err.log;
  then curl --location --request POST 'https://api.github.com/repos/xxx/xxx/actions/workflows/xxxx/dispatches' \
  --header 'Accept: application/vnd.github.v3+json' \
  --header 'Authorization: token ${{ secrets.GH_PAT }}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "ref": "main",
      "inputs": {
          "xxx": "${{github.event.inputs.xxx}}"
      }
  }'
  fi
error parsing called workflow "bxb100/xxx/.github/workflows/download.yml@main": job "retry" calls workflow "bxb100/xxx/.github/workflows/download.yml@main", but doing so would exceed the limit on called workflow depth of 2

如何上传可执行文件到 release 中 (draft)

  1. 首先需要先创建一个 git ref tag 对应的 draft release, 注意此时的 tag 如果没有的话 GitHub 也不会主动给你绑定 image

see https://gist.github.com/bxb100/d2fedcb3cdc897062ee03920d6ae83be

  1. upload the artifact
  2. download artifacts, and compress them
  3. using gh upload to the release
     - name: Upload
        run: |
          until gh release upload --clobber --repo ${{ github.repository }} ${{ github.event.inputs.tag }} *.zip *.tar.gz; do
            echo "Attempt $((++attempts)) to upload release artifacts failed. Will retry in 20s"
            sleep 20
          done
        timeout-minutes: 10
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Examples


Github Action Cache Path

https://github.com/actions/toolkit/blob/e98bae803b6520b2a331f66011d812c3af8bf6ae/packages/cache

At the beginning, I tried to understand this path as a specified file glob expression, like this: ~/.m2/repository/**

but correct the way is upload directory like this: ~/.m2/repository/*/*/*

So don’t miss the point of what your need


Auto push to Marketplace

一般来说, GitHub action 如果要上传到 marketplace 的话需要生成 dist 目录, 但是可以通过 https://github.com/JasonEtco/build-and-tag-action 项目自动生成 dist 然后自动上传 (去除了非 dist, action.xml, 仓库大小减少了~~)

注意默认 github.token 权限问题: https://github.com/JasonEtco/build-and-tag-action/issues/40 注意一定要有 write 权限…


Reusable workflow

If you using a useable workflow, input with env will cause an error (test secrets, needs.xx.outputs.xxx working now)7

The workflow is not valid. xxxx: Unrecognized named-value: 'env'.

My work on https://github.com/BurtonQin/lockbud/pull/49 show that problems

solve the problem using a config like this:

with:
  rust_version: ${{ needs.test.outputs.rust_version }}

Docker

In the Action, we have three ways to use the docker

  1. using container8, need to notice that runner is running a docker image
  2. using service9, it like expose a port to workflow runtime, so we don’t change the runner env
  3. using docker action10

在 PR 中使用 secret 的一些手段

  1. 使用 pull_request_target11, 我在 https://github.com/bxb100/action-test/pull/16/checks 中测试过, 需要配合 enviroment secret 的授权来做更严格的限制
  2. 通过 repository_dispatch 触发12, 可以参看 https://github.com/1Password/load-secrets-action/blob/85e0e789db06bad7e43b5f7b0c36700967d04155/.github/workflows/ok-to-test.yml 用例, 可以通过 api 也可以通过一个新的 action 来 trigger (没想到的地方是, 这个能关联到正确的 commit-hash 中, 需要进步理解)

Footnotes

  1. https://docs.github.com/en/actions/security-guides/encrypted-secrets#:~:text=Secrets%20cannot%20be%20directly%20referenced%20in%20if%3A%20conditionals.%20Instead%2C%20consider%20setting%20secrets%20as%20job%2Dlevel%20environment%20variables%2C%20then%20referencing%20the%20environment%20variables%20to%20conditionally%20run%20steps%20in%20the%20job.

  2. https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-secrets

  3. https://github.community/t/how-to-retry-a-failed-step-in-github-actions-workflow/125880

  4. https://stackoverflow.com/questions/11287861/how-to-check-if-a-file-contains-a-specific-string-using-bash

  5. https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event Create a workflow dispatch event

  6. https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context

  7. https://github.com/orgs/community/discussions/26671

  8. https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container

  9. https://docs.github.com/en/actions/using-containerized-services/about-service-containers

  10. https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action

  11. https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target

  12. https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#repository_dispatch


Edit page
Share this post on:

Previous Post
android 使用通知滤盒, gotify 和 raycast 接收验证码
Next Post
Java 使用中的一些奇巧淫技