SBRG / MASSpy

https://masspy.readthedocs.io
MIT License
22 stars 6 forks source link

Automate release to BioSimulators #161

Closed jonrkarr closed 3 years ago

jonrkarr commented 3 years ago

To keep the version of MASSpy in BioSimulators up to date, we recommend automating the release of new versions to BioSimulators. This can be done using the GitHub API, such as using the action step below.

Two repository "secrets" need to be added to use the action:

This will trigger a CI action on BioSimulators_MASSpy which will test the interface and build a Docker image. Depending on the order in which you release to PyPI and BioSimulators, we may need to make minor changes to this downstream action because there's typically a short delay because PyPI packages are available.

name: Update BioSimulators interface and Docker image

on:
  release:
    types:
      - published

jobs:
  updateBioSimulatorsCliAndDockerImage:
    name: Trigger the building and release of the BioSimulators interface to MASSpy
    runs-on: ubuntu-latest
    steps:
      - name: Trigger a GitHub action that will build and release the BioSimulators interface to MASSpy
        run: |
          PACKAGE_VERSION="${GITHUB_REF/refs\/tags\/v/}"
          curl -X POST \
               -u ${{ secrets.BIOSIMULATORS_GH_USERNAME }}:${{ secrets.BIOSIMULATORS_GH_TOKEN }} \
               -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/biosimulators/Biosimulators_MASSpy/actions/workflows/ci.yml/dispatches \
               -d "{\"ref\": \"dev\", \"inputs\": {\"simulatorVersion\": \"${PACKAGE_VERSION}\", \"simulatorVersionLatest\": \"true\"}}"
sbrg-machine-user commented 3 years ago

Bot account

z-haiman commented 3 years ago

Hi @jonrkarr

Would it be possible to add the sbrg-machine-user as a bot account for this purpose?

jonrkarr commented 3 years ago

Yes, it can be any GitHub account. I can give permissions to that account. You'll need to accept the GitHub invitation.

jonrkarr commented 3 years ago

We also use machine accounts for similar purposes.

jonrkarr commented 3 years ago

Here's a preview of what publishing a MASS model will look like. Note, BioSimulations is still a work in progress.

https://biosimulations.org/projects/RBC-metabolism-Bordbar-Cell-Syst-2015

z-haiman commented 3 years ago

How can I generate the token? Alternatively, could it be emailed to me or the bot account?

Much appreciated :)

jonrkarr commented 3 years ago

GitHub tokens have to be generated by users. This can be done at https://github.com/settings/tokens while logged into GitHub as sbrg-machine-user account. When you create the token, grant it the repo "scope". Scopes are permissions granted to the token.

The token can then be stored as a "secret" as outlined above. The secrets can be stored here https://github.com/SBRG/MASSpy/settings/secrets/actions. Secrets are GitHub's mechanism to store passwords for actions without embedding them into repositories. This allows the secret to be private, while the repository is public. Secrets can they be used similarly to environment variables in GitHub actions.

"Secrets"

z-haiman commented 3 years ago

Oh! Those tokens, I thought you were talking about something biosimulators specific.

Thanks!

jonrkarr commented 3 years ago

Sorry that wasn't clear. Because nearly all systems biology software projects are being developed in GitHub, it seemed easiest to leverage existing accounts.

z-haiman commented 3 years ago

No worries! That's what the bot account is for anyways, plus I also see now that I misread the original message XD

z-haiman commented 3 years ago

@jonrkarr let me know if this works!

jonrkarr commented 3 years ago

The action failed due to insufficient permissions. I corrected the permissions. Could you try again?

One thing we find convenient for testing workflows is adding a "workflow dispatch" option. This provides the ability to click a button in the GitHub website to trigger the workflow, in addition to the other event-based triggers. Adding workflow_dispatch: to the action (see below) would give you a button ("Run workflow") to trigger the workflow here: https://github.com/SBRG/MASSpy/actions/workflows/biosimulators_dispatch.yml. This would let you run the workflow separate from creating a new GitHub release.

Add to workflow dispatch: to .github/workflows/biosimulators_dispatch.yml:

...
on:
  release:
    types:
      - published
  workflow_dispatch:
...
z-haiman commented 3 years ago

Added in the dispatch and reran the workflow

jonrkarr commented 3 years ago

The workflow ran. I think the issue can be closed now.