Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input of upload release switch and output of file related information #158

Merged
merged 7 commits into from
Feb 7, 2024

Conversation

lslqtz
Copy link
Contributor

@lslqtz lslqtz commented Jan 28, 2024

通过添加文件名及文件路径至 GITHUB_OUTPUT, 可以使后续的 workflow 可以再次处理此文件.
例如: 用户可以不发布 Release, 而是手动触发 Action (workflow_dispatch 事件), 并通过 actions/upload-artifact 从 Artifacts 得到/发布一份 Nightly Build 用于测试.
https://github.com/lslqtz/go-testproject/actions/runs/7683774998

通过此实现也可以部分缓解 #53 问题, 如用户可以将文件放入缓存或其它地方, 并在其它不同 OS 的 job 下进行调用 (也许 macOS 下才能进行 Xcode 代码签名).

(标题名不太好, 几个问题, 1 是在 workflow_dispatch 事件下不触发 Release 上传是否合理, 2 是因为 actions/upload-artifact 本身会再次打包 zip, 因此若能传递文件夹会更好)

jobs:
  Release-Go-Binary:
    runs-on: 'ubuntu-latest'
    steps:
    - name: 'Checkout'
      uses: 'actions/checkout@v4'
    - name: 'Build'
      uses: 'lslqtz/go-release-action@master'
      id: release
      with:
        goos: 'linux'
        goarch: 'amd64'
        goversion: 1.19
        md5sum: false
        sha256sum: false
        binary_name: 'go-testproject'
    - name: 'Echo outputs'
      run: echo ${{join(steps.release.outputs.*, '\n')}}
    - name: 'Upload GitHub Artifact'
      uses: actions/upload-artifact@v4
      with:
        name: ${{ steps.release.outputs.release_asset_file }}
        path: ${{ steps.release.outputs.release_asset_path }}

@lslqtz
Copy link
Contributor Author

lslqtz commented Jan 28, 2024

在添加 release_asset_dir 并为 actions/upload-artifact 使用后, 它确实可以将 BUILD_ARTIFACTS_FOLDER 下的文件全部打包了, 并同时打包了包括一份 tar.gz... (https://github.com/lslqtz/go-testproject/actions/runs/7683854200)

我没有想到合理的方法解决此问题, 除非将压缩包单独放入一个目录或将其文件放在上层而非文件夹内.
已通过将压缩包单独放入一个目录, 声明更多的 output, 并修改 workflow 来解决此问题. (https://github.com/lslqtz/go-testproject/actions/runs/7684437900)

    - name: 'Upload GitHub Artifact'
      uses: actions/upload-artifact@v4
      with:
        name: ${{ steps.release.outputs.release_asset_name }}
        path: ${{ steps.release.outputs.release_asset_dir }}/
1 % ls
go-testproject-master-linux-amd64-3.zip
1 % unzip go-testproject-master-linux-amd64-3.zip 
Archive:  go-testproject-master-linux-amd64-3.zip
  inflating: README.md               
  inflating: go-testproject 

@lslqtz lslqtz force-pushed the master branch 3 times, most recently from 554db07 to 821d7a7 Compare January 28, 2024 08:06
@lslqtz
Copy link
Contributor Author

lslqtz commented Jan 28, 2024

在测试正常发布时, 还遇到了 GITHUB_REF 有值, 但是 INPUT_RELEASE_NAME 为空且环境变量无法搜索到 RELEASE NAME v1.0t 的情况 (https://github.com/lslqtz/go-testproject/actions/runs/7684502223/job/20941069213), 原因不明确, 相关 Issue 可能有 #76, 不得不同时打一个 Patch 去解决此问题以便测试.
在此 Patch 后, 测试正常工作, 经过一顿修复... PR 原要实现的内容, 发布触发和手动触发看起来也都能正常工作了.
正常发布触发: https://github.com/lslqtz/go-testproject/actions/runs/7684625438 (https://github.com/lslqtz/go-testproject/releases/tag/v1.0t5)
手动触发: https://github.com/lslqtz/go-testproject/actions/runs/7684637956

附上该问题的相关信息.

GITHUB_ACTION=release
GITHUB_REF_TYPE=tag
GITHUB_ACTIONS=true
GITHUB_SHA=4779abe301d782945a78c146c83d486dacb90569
INPUT_GOARCH=amd64
GITHUB_WORKFLOW_REF=lslqtz/go-testproject/.github/workflows/release.yaml@refs/tags/v1.0
INPUT_COMPRESS_ASSETS=TRUE
GITHUB_REF=refs/tags/v1.0
RUNNER_OS=Linux
GITHUB_REF_PROTECTED=false
HOME=/github/home
GITHUB_API_URL=https://api.github.com
INPUT_RELEASE_TAG=
RUNNER_ARCH=X64
INPUT_GOVERSION=1.19
INPUT_BINARY_NAME=go-testproject
GITHUB_STATE=/github/file_commands/save_state_461e72c9-e25c-4ab1-b95d-97b310a546c2
GITHUB_ENV=/github/file_commands/set_env_461e72c9-e25c-4ab1-b95d-97b310a546c2
GITHUB_EVENT_PATH=/github/workflow/event.json
GITHUB_EVENT_NAME=release
INPUT_RELEASE_REPO=
INPUT_GITHUB_TOKEN=
INPUT_OVERWRITE=FALSE
INPUT_POST_COMMAND=
GITHUB_WORKFLOW_SHA=4779abe301d782945a78c146c83d486dacb90569
GITHUB_REF_NAME=v1.0
INPUT_ASSET_NAME=
GITHUB_JOB=Release-Go-Binary
INPUT_RELEASE_NAME=
INPUT_LDFLAGS=
GITHUB_REPOSITORY=lslqtz/go-testproject
GITHUB_ACTION_REPOSITORY=lslqtz/go-release-action
GITHUB_BASE_REF=
CI=true
GITHUB_REPOSITORY_OWNER=lslqtz
GITHUB_HEAD_REF=
GITHUB_ACTION_REF=master
GITHUB_WORKFLOW=Release-Go-Binary
GITHUB_OUTPUT=/github/file_commands/set_output_461e72c9-e25c-4ab1-b95d-97b310a546c2
GOPATH=/go

@lslqtz lslqtz force-pushed the master branch 2 times, most recently from ebabb48 to 515900b Compare January 28, 2024 08:51
@lslqtz
Copy link
Contributor Author

lslqtz commented Jan 29, 2024

通过一并替换 INPUT_POST_COMMAND 中的特定匹配字符串, 可以使 post_command 也能使用这些变量, 并同时解决此问题
#116.
(可能存在的问题是: 替换时空格未经转义, 用户应该可以通过包裹在引号内来修复它).
Action: https://github.com/lslqtz/go-testproject/actions/runs/7691387501/job/20956630396

+ eval echo '"echo' ./build-artifacts-1706504492, ./archive_build-artifacts-1706504492, go-testproject-master-linux-amd64, go-testproject-master-linux-amd64.tar.gz, 'archive_build-artifacts-1706504492/go-testproject-master-linux-amd64.tar.gz"'

手动测试命令:

~ % RELEASE_ASSET_DIR='/assets'
RELEASE_ASSET_ARCHIVE_DIR='/archive_assets'
RELEASE_ASSET_NAME='go-testproject-v1-darwin-arm64'
RELEASE_ASSET_FILE='go-testproject-v1-darwin-arm64.tar.gz'
RELEASE_ASSET_PATH='/archive_assets/go-testproject-v1-darwin-arm64.tar.gz'

INPUT_POST_COMMAND="echo {RELEASE_ASSET_DIR}, {RELEASE_ASSET_ARCHIVE_DIR}, {RELEASE_ASSET_NAME}, {RELEASE_ASSET_FILE}, {RELEASE_ASSET_PATH}"

echo ${INPUT_POST_COMMAND}
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_DIR}"/${RELEASE_ASSET_DIR}}
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_ARCHIVE_DIR}"/${RELEASE_ASSET_ARCHIVE_DIR}}
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_NAME}"/${RELEASE_ASSET_NAME}}
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_FILE}"/${RELEASE_ASSET_FILE}}
INPUT_POST_COMMAND=${INPUT_POST_COMMAND/"{RELEASE_ASSET_PATH}"/${RELEASE_ASSET_PATH}}
echo ${INPUT_POST_COMMAND}

手动测试结果:

echo {RELEASE_ASSET_DIR}, {RELEASE_ASSET_ARCHIVE_DIR}, {RELEASE_ASSET_NAME}, {RELEASE_ASSET_FILE}, {RELEASE_ASSET_PATH}
echo /assets, /archive_assets, go-testproject-v1-darwin-arm64, go-testproject-v1-darwin-arm64.tar.gz, /archive_assets/go-testproject-v1-darwin-arm64.tar.gz

@lslqtz lslqtz changed the title Add filename/filepath to github output; Don't upload release when workflow_dispatch is triggered Add file related information to variables; Don't upload release when workflow_dispatch is triggered Jan 29, 2024
action.yml Show resolved Hide resolved
release.sh Outdated Show resolved Hide resolved
@wangyoucao577
Copy link
Owner

通过添加文件名及文件路径至 GITHUB_OUTPUT, 可以使后续的 workflow 可以再次处理此文件. 例如: 用户可以不发布 Release, 而是手动触发 Action (workflow_dispatch 事件), 并通过 actions/upload-artifact 从 Artifacts 得到/发布一份 Nightly Build 用于测试. https://github.com/lslqtz/go-testproject/actions/runs/7683774998

通过此实现也可以部分缓解 #53 问题, 如用户可以将文件放入缓存或其它地方, 并在其它不同 OS 的 job 下进行调用 (也许 macOS 下才能进行 Xcode 代码签名).

(标题名不太好, 几个问题, 1 是在 workflow_dispatch 事件下不触发 Release 上传是否合理, 2 是因为 actions/upload-artifact 本身会再次打包 zip, 因此若能传递文件夹会更好)

jobs:
  Release-Go-Binary:
    runs-on: 'ubuntu-latest'
    steps:
    - name: 'Checkout'
      uses: 'actions/checkout@v4'
    - name: 'Build'
      uses: 'lslqtz/go-release-action@master'
      id: release
      with:
        goos: 'linux'
        goarch: 'amd64'
        goversion: 1.19
        md5sum: false
        sha256sum: false
        binary_name: 'go-testproject'
    - name: 'Echo outputs'
      run: echo ${{join(steps.release.outputs.*, '\n')}}
    - name: 'Upload GitHub Artifact'
      uses: actions/upload-artifact@v4
      with:
        name: ${{ steps.release.outputs.release_asset_file }}
        path: ${{ steps.release.outputs.release_asset_path }}

1 是在 workflow_dispatch 事件下不触发 Release 上传是否合理 ==> 不太合理,并不是只有手动触发才有这个需求。可以单独加一个 upload: true/false 的 option 来控制。

@lslqtz
Copy link
Contributor Author

lslqtz commented Feb 2, 2024

通过添加文件名及文件路径至 GITHUB_OUTPUT, 可以使后续的 workflow 可以再次处理此文件. 例如: 用户可以不发布 Release, 而是手动触发 Action (workflow_dispatch 事件), 并通过 actions/upload-artifact 从 Artifacts 得到/发布一份 Nightly Build 用于测试. https://github.com/lslqtz/go-testproject/actions/runs/7683774998
通过此实现也可以部分缓解 #53 问题, 如用户可以将文件放入缓存或其它地方, 并在其它不同 OS 的 job 下进行调用 (也许 macOS 下才能进行 Xcode 代码签名).
(标题名不太好, 几个问题, 1 是在 workflow_dispatch 事件下不触发 Release 上传是否合理, 2 是因为 actions/upload-artifact 本身会再次打包 zip, 因此若能传递文件夹会更好)

1 是在 workflow_dispatch 事件下不触发 Release 上传是否合理 ==> 不太合理,并不是只有手动触发才有这个需求。可以单独加一个 upload: true/false 的 option 来控制。

已添加 upload 开关来控制, 通过在 workflow 里使用 ${{ github.event_name }} 控制 input 应该可以很好的控制意图.

同时也更新了 README.md 反映新增的这些参数, 不过不太确定如何表达这些输出参数在 post_command 可用较好.
(post_command 中使用 {RELEASE_ASSET_DIR}/{RELEASE_ASSET_NAME}/{RELEASE_ASSET_FILE}/{RELEASE_ASSET_PATH} 的特殊字符串可在执行前被替换为实际的变量)

@lslqtz lslqtz changed the title Add file related information to variables; Don't upload release when workflow_dispatch is triggered Add input to upload release switch and output of file related information Feb 2, 2024
@lslqtz lslqtz changed the title Add input to upload release switch and output of file related information Add input of upload release switch and output of file related information Feb 2, 2024
@lslqtz lslqtz force-pushed the master branch 3 times, most recently from 3d9283c to d5df250 Compare February 3, 2024 11:24
@lslqtz lslqtz force-pushed the master branch 5 times, most recently from 65d64b9 to c2304dc Compare February 4, 2024 18:00
@lslqtz lslqtz force-pushed the master branch 2 times, most recently from 6a717a3 to ac9e946 Compare February 4, 2024 18:20
@wangyoucao577 wangyoucao577 merged commit 5efa231 into wangyoucao577:master Feb 7, 2024
1 check passed
@wangyoucao577
Copy link
Owner

Closes #53

@wangyoucao577
Copy link
Owner

非常感谢贡献!可以尝试下wangyoucao577/[email protected]

@lslqtz
Copy link
Contributor Author

lslqtz commented Feb 7, 2024

看起来工作良好! 我在指定 upload: true 的情况下可以同时上传 Release 及通过其它 job 上传 GitHub Artifacts.
https://github.com/lslqtz/go-testproject/actions/runs/7816917369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants