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

Artifacts download api for artifact actions v4 #33510

Merged
merged 47 commits into from
Feb 16, 2025

Conversation

ChristopherHX
Copy link
Contributor

@ChristopherHX ChristopherHX commented Feb 5, 2025

  • download endpoint has to use 302 redirect
  • fake blob download used if direct download not possible
  • downloading v3 artifacts not possible

New repo apis based on GitHub Rest V3

  • GET /runs/{run}/artifacts (Cannot use run index of url due to not being unique)
  • GET /artifacts
  • GET + DELETE /artifacts/{artifact_id}
  • GET /artifacts/{artifact_id}/zip
  • (GET /artifacts/{artifact_id}/zip/raw this is a workaround for a http 302 assertion in actions/toolkit)
    • api docs removed this is protected by a signed url like the internal artifacts api and no longer usable with any token or swagger
    • returns http 401 if the signature is invalid
      • or change the artifact id
      • or expired after 1 hour

Closes #33353
Closes #32124

* download endpoint has to use 302 redirect
* fake blob download used if direct download not possible
* downloading v3 artifacts not possible

New apis based on GitHub Rest V3
/runs/{run}/artifacts (Cannot use run index of url due to not beeing unique)
/artifacts
/artifacts/{artifact_id}/zip
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 5, 2025
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 5, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Feb 5, 2025
@ChristopherHX
Copy link
Contributor Author

usage in

on: push
jobs:
  test:
    runs-on: mac-docker
    steps:
    - uses: christopherhx/gitea-download-artifact@v4
      with:
        name: mygithub-context
        github-token: ${{ secrets.GITHUB_TOKEN }} # token with actions:read permissions on target repo
        #repository: actions/toolkit
        run-id: 4 # To get this id could be a challenge, in github.com it's part of the web ui url, we only have a run_number / index
    - run: ls -l
    - run: cat file.txt

@silverwind silverwind added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Feb 5, 2025
@silverwind
Copy link
Member

silverwind commented Feb 5, 2025

templates/swagger/v1_json.tmpl:
Wrong line endings or no final newline

IIRC, this is a outstanding bug that the swagger command sometimes introduces platform-specific line-endings. I think we need to normalize the file.

@wxiaoguang
Copy link
Contributor

Could there be some tests to cover the newly added APIs?

@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Feb 14, 2025

func DownloadArtifactV4ServeDirectOnly(ctx *context.Base, art *actions_model.ActionArtifact) (bool, error) {
if setting.Actions.ArtifactStorage.ServeDirect() {
u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this err should be returned if it's not nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, currently the error return value seems to be accidentally not returned.

But I want to make sure we get the expected behavior here, therefore I want some discussion about this before making changes

If we just return the error here (without changing the callers), this error may get returned by the api instead of triggering the fallback ( tunneling blob via gitea ).

What do we want to do with this error?

  • Return it from the api and abort the request? (needs changes)
  • Try the fallback and fail if the fallback doesn't work? (current behavior)
    • Log the error from the caller and continue with the fallback? if the boolean returns false (...and return the error from api if it returns true) (needs changes)
    • Otherwise Remove the error return value from the function? (needs changes)
    • Most ServeDirect() paths I saw in gitea dropped the error and only used it to detect if the url has been returned without error e.g. search for text ServeDirect in this repo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to keep as other behaviors, no need to introduce too many changes at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think it's OK to keep the current behavior. Maybe we can add some logs for this error later to help us debug cases where SERVE_DIRECT doesn't work.

@github-actions github-actions bot added the modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin label Feb 15, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 15, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 15, 2025
@wxiaoguang wxiaoguang merged commit 2b8cfb5 into go-gitea:main Feb 16, 2025
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 16, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 17, 2025
* giteaofficial/main:
  Add API to support link package to repository and unlink it (go-gitea#33481)
  [skip ci] Updated translations via Crowdin
  Update JS and PY dependencies (go-gitea#33587)
  [chore] add git mailmap for proper attribution of authorship (go-gitea#33612)
  Move commits signature and verify functions to service layers (go-gitea#33605)
  add spacing between sign in button's icon and text (go-gitea#33609)
  enable literal string for code search (go-gitea#33590)
  [skip ci] Updated translations via Crowdin
  Artifacts download api for artifact actions v4 (go-gitea#33510)
  Fix bug when get commit (go-gitea#33602)
  Fix mirror bug (go-gitea#33597)
  Fix typo in HTML attribute (go-gitea#33599)
  Use default Git timeout when checking repo health (go-gitea#33593)
  Improve commits list performance to reduce unnecessary database queries (go-gitea#33528)
  Performance optimization for pull request files loading comments attachments (go-gitea#33585)
  Fix PR's target branch dropdown (go-gitea#33589)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/go Pull requests that update Go code size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
7 participants