-
-
Notifications
You must be signed in to change notification settings - Fork 57
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 auto upload assets #601
Open
AsenHu
wants to merge
2
commits into
girlbossceo:main
Choose a base branch
from
AsenHu:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Upload Release Assets | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'Tag to release' | ||
required: true | ||
type: string | ||
action_id: | ||
description: 'Action ID of the CI run' | ||
required: true | ||
type: string | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: get latest ci id | ||
id: get_ci_id | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
if [ "${{ github.event_name }}" == "workflow_dispatch" ] | ||
then | ||
id="${{ github.event.inputs.action_id }}" | ||
tag="${{ github.event.inputs.tag }}" | ||
else | ||
# get all runs of the ci workflow | ||
json=$(gh api "repos/${{ github.repository }}/actions/workflows/ci.yml/runs") | ||
|
||
# find first run that is github sha and status is completed | ||
id=$(echo "$json" | jq ".workflow_runs[] | select(.head_sha == \"${{ github.sha }}\" and .status == \"completed\") | .id" | head -n 1) | ||
if [ ! "$id" ]; then | ||
echo "No completed runs found" | ||
echo "ci_id=0" >> "$GITHUB_OUTPUT" | ||
exit 0 | ||
fi | ||
|
||
tag="${{ github.event.release.tag_name }}" | ||
fi | ||
|
||
echo "ci_id=$id" >> "$GITHUB_OUTPUT" | ||
echo "tag=$tag" >> "$GITHUB_OUTPUT" | ||
|
||
- name: get latest ci artifacts | ||
if: steps.get_ci_id.outputs.ci_id != 0 | ||
uses: actions/download-artifact@v4 | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
with: | ||
merge-multiple: true | ||
run-id: ${{ steps.get_ci_id.outputs.ci_id }} | ||
github-token: ${{ github.token }} | ||
|
||
- run: | | ||
ls | ||
|
||
- name: upload release assets | ||
if: steps.get_ci_id.outputs.ci_id != 0 | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
TAG: ${{ steps.get_ci_id.outputs.tag }} | ||
run: | | ||
for file in $(find . -type f); do | ||
echo "Uploading $file..." | ||
gh release upload $TAG "$file" --clobber --repo="${{github.repository}}" || echo "Something went wrong, skipping." | ||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the problem I think I see with these steps is there is no check anywhere if the latest CI run is a tag, or if we're even running in a
tag
at all.To me, it just looks like it's going to try automatically uploading binaries every single CI run. I don't know how safe that is.
Here's an example of our Docker publish step, we perform actions based on whether we're in a tag or not: https://github.com/girlbossceo/conduwuit/blob/main/.github/workflows/ci.yml#L511
In this case, I only want to run this if I'm running the workflow from a tag.
I also don't really see anything that replaces existing binaries uploaded. So, if I run a workflow, and re-run it, will it upload two binaries?
Can some safety precautions be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow is triggered by publishing, it does not run on every single CI run.
This means that it will only run if you are on the releases page, click publish release, and select a tag.
No, if there is already a file with the same name in the release, it will be overwritten. It is done by the clobber of gh cli.
This document describes the function of clobber.
Of course, I can make the workflow exit with an error when it is triggered by commit. Or I can make it run only when the workflow is triggered by publishing, so that even if the workflow is accidentally triggered, there will be no problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay then I likely misunderstood then. I guess I can just try it out as is and see what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just enter the action id, and v0.4.7-rc and run it manually, it will upload the action artifact you selected to v0.4.7-rc. You can also run it repeatedly to see if it replaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can let me do this in my fork, which would be safer.