Skip to content

@bioimageiobot, please upload resourceful-lizard #26

@bioimageiobot, please upload resourceful-lizard

@bioimageiobot, please upload resourceful-lizard #26

on:
issues:
types:
- opened
- reopened
permissions:
issues: write # Allow the workflow to update the opened issue
jobs:
comment:
if: startsWith(github.event.issue.title, '@bioimageiobot, please upload')
outputs:
package_url: ${{steps.analyse-body.outputs.package_url}}
runs-on: ubuntu-latest
steps:
- id: analyse-body
shell: python
run: |
import os
import uuid
body = os.environ["BODY"]
expected_start = "### Temporary Public Download URL\n\n"
expected_end = """
### Terms of Service
- [x] I confirm that I have read and agree to bioimage.io's [Terms of Service](https://bioimage.io/docs/#/terms_of_service)"""
if body.startswith(expected_start) and body.endswith(expected_end):
package_url = body[len(expected_start):-len(expected_end)].strip()
if not package_url or not package_url.startswith("https://"):
msg = f"I was expecting to find an https URL to a ZIP-file containing a packaged bioimage.io description, but I found '{package_url}'."
package_url = ""
else:
msg = f"Started [workflow run](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) to upload '{package_url}' to the bioimage.io collection."
else:
msg = f"Expected issue to follow the '@bioimageiobot, please upload' issue template with a checked Terms of Service checkbox.\nPlease create a new issue if you do want to upload a bioimage.io package. Thank you! :pray:"
package_url = ""
def set_output(name, value):
"""adapted from https://github.com/orgs/community/discussions/28146#discussioncomment-5638014"""
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
delimiter = uuid.uuid1()
print(f'{name}<<{delimiter}', file=fh)
print(value, file=fh)
print(delimiter, file=fh)
set_output("message", msg)
set_output("package_url", package_url)
env:
BODY: ${{github.event.issue.body}}
- run: gh issue comment "$NUMBER" --body "$MESSAGE"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
MESSAGE: ${{steps.analyse-body.outputs.message}}
stage:
needs: comment
if: needs.comment.outputs.package_url != ''
uses: bioimage-io/collection/.github/workflows/stage_call.yaml@main
with:
package_url: ${{needs.comment.outputs.package_url}}
environment_name: production
bioimageio_user_id: ${{format('github|{0}', github.event.issue.user.id)}}
secrets: inherit
report:
needs: [comment, stage]
if: startsWith(github.event.issue.title, '@bioimageiobot, please upload') && always()
runs-on: ubuntu-latest
steps:
- if: needs.stage.result != 'success'
run: gh issue comment "$NUMBER" --body "$MESSAGE"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
MESSAGE: |
Unfortunately an error occurred, see stage job in [workflow run](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}).
bioimage.io @reviewers were notified.
- if: needs.stage.result == 'success'
run: |
gh issue close "$NUMBER" --reason=completed --comment="$MESSAGE"
gh issue edit "$NUMBER" --title="$TITLE"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
MESSAGE: |
Successfully staged new draft '${{needs.stage.outputs.concept_id}}' from ${{needs.comment.outputs.package_url}} ! :rocket:
Status and test results of your upload can be found [here](https://bioimageio-uploader.netlify.app/#/status/${{needs.stage.outputs.concept_id}}).
TITLE: "@bioimageiobot, please upload ${{needs.stage.outputs.concept_id}}"
test:
needs: stage
uses: bioimage-io/collection/.github/workflows/test_call.yaml@main
with:
concept_id: ${{needs.stage.outputs.concept_id}}
version: 'draft'
environment_name: 'production'
issue-nr: ${{github.event.issue.number}}
secrets: inherit