Skip to content

Add support for Github actions #109

Closed

Description

@relekang
  • Add necessary checks for github actions.
  • Setup github actions for releasing this project by calling on the current source code.
  • Add to the documentation how to setup semantic release with github actions.

Activity

  1. self-assigned this
    on Feb 8, 2019
  2. added
    featureA new feature or a feature request
    needs-docsDocumentation needs to be updated
    on Feb 8, 2019
  3. iamogbz commented on Sep 13, 2019

    @iamogbz
    Contributor

    Attempted to use this package with github actions and publish fails with no visible error message! 😞

    After much head scratching I was able to identify that it errors at the get_repository_owner_and_name step.
    https://github.com/relekang/python-semantic-release/blob/24336d43f6e69ef1216d56b47892ee864af09c7d/semantic_release/vcs_helpers.py#L87-L90

    Apparently github ci uses https://github.com/iamogbz/nvshim without the .git suffix as the repo url which does not match the regex specified above!

    Suggested change would be

    parts = re.search(r'[:/]([^\.:]+)/([^/]+)(.git)?$', url)

    Can create an issue and open to submitting a PR

  4. relekang commented on Sep 14, 2019

    @relekang
    MemberAuthor

    It would be awesome if you have the time to create a PR for it 😄

  5. iamogbz commented on Sep 16, 2019

    @iamogbz
    Contributor

    @relekang also I had temporarily fixed this in my CI by appending .git to the origin but had some other issues that prevented me from using the package e.g. --noop still pushing tags etc. I will create issues as I don't think those are github actions specific.

  6. alandtse commented on Sep 29, 2019

    @alandtse
    Contributor

    I'm testing the merged version and using GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} which uses the default GITHUB_TOKEN. This results in the following error while trying to push:

    stderr: 'fatal: could not read Password for 'https://[AUTH_TOKEN]@github.com': No such device or address'
    

    I believe the problem is the default GITHUB_TOKEN expects to be used with a GITHUB_ACTOR as the username. I'm basing this observation on this code.

    I'll play around and see if it's as simple as adding GITHUB_ACTOR as the user in the https string.

  7. alandtse commented on Sep 29, 2019

    @alandtse
    Contributor

    I ended up getting farther with my repo changes. However, ran into a branch protection issue.

    stderr: 'remote: error: GH006: Protected branch update failed for refs/heads/master.        
    remote: error: You're not authorized to push to this branch. Visit https://help.github.com/articles/about-protected-branches/ for more information.        
    

    I wasn't sure if the problem was because I'm committing to an organization, so I gave up with the GITHUB_TOKEN (I'm an admin on the repo I'm pushing to so not sure why the GITHUB_TOKEN isn't enough to log in as my account and didn't want to debug it further) and created a personal access token. With that I was able to commit using my changes.

    However, I don't know if my changes are necessary with a personal access token so I'm leaving this comment in case someone wants to try the code with a GITHUB_TOKEN. If it works, happy to do a PR or you can just integrate my code directly.

  8. danth commented on Jan 16, 2020

    @danth
    Contributor

    @alandtse I've tried your changes with a GITHUB_TOKEN, and can confirm that it works correctly.

  9. alandtse commented on Jan 16, 2020

    @alandtse
    Contributor

    @AlphaMycelium Great, I'll put in a PR.

  10. danth commented on Jan 17, 2020

    @danth
    Contributor

    With the new GITHUB_ACTOR checks, I have been able to create a working GitHub Action here, if anyone is interested in taking a look. I haven't tested it with every possible configuration.

  11. danth commented on Jan 25, 2020

    @danth
    Contributor

    One problem I'm having is that the release notes are replaced with a short message containing only the name of the tag, as seen here. I'm not quite sure what is causing this, but it only happens when running from GitHub Actions.

    https://github.com/AlphaMycelium/psr-action/issues/1

  12. relekang commented on Jan 25, 2020

    @relekang
    MemberAuthor

    It is not replaced, that tag is missing release notes so it is showing the annotated message from the git tag. If you view the list of tags in github it shows which have release notes and which does not. My guess is that the upload of changelog failed.

  13. 7 remaining items

  14. danth commented on Feb 12, 2020

    @danth
    Contributor

    @KingDarBoja I see, I'm thinking the easiest way to do this is to pass a subdirectory as an input and cd into it as part of the entrypoint script. Then to run for multiple projects you can just repeat the step with a different directory.

    I'll implement that quickly and push it to a branch for you to try.

  15. danth commented on Feb 12, 2020

    @danth
    Contributor

    @KingDarBoja Ok, it's on a branch called monorepo. Give that a try and see if it works, if so I'll add some docs and release it to the marketplace.

        - name: Release Project 1
          uses: AlphaMycelium/psr-action@monorepo
          with:
            directory: ./project1
            github_token: ${{ secrets.GITHUB_TOKEN }}
            pypi_username: <ADD YOUR USERNAME HERE>
            pypi_password: ${{ secrets.PYPI_PASSWORD }} 
        
        - name: Release Project 2
          uses: AlphaMycelium/psr-action@monorepo
          with:
            directory: ./project2
            github_token: ${{ secrets.GITHUB_TOKEN }}
            pypi_username: <ADD YOUR USERNAME HERE>
            pypi_password: ${{ secrets.PYPI_PASSWORD }} 
  16. KingDarBoja commented on Feb 14, 2020

    @KingDarBoja
    Contributor

    @AlphaMycelium Hi mate, just tested it and now it was able to cd to the correct dir, however, now I am facing some error that I think isn't related to the actions but semantic release:

    Current version: 1.0.0
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:cli 'main args:' {'force_level': None, 'post': False, 'retry': False, 'noop': False, 'define': ()} +0.0us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:cli 'main env:' 'PYPI_USERNAME="",PYPI_PASSWORD="",GH_TOKEN="$GH_TOKEN",GL_TOKEN="None",' +68.75us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:cli 'main config:' {'check_build_status': 'false', 'commit_message': 'Automatically generated by python-semantic-release', 'commit_parser': 'semantic_release.history.angular_parser', 'patch_without_tag': 'false', 'upload_to_pypi': 'false', 'version_source': 'commit'} +84.5us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:history 'get_current_version_by_config_file' +0.0us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:history 'lib/__init__.py' '__version__' +24.0us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:history <re.Match object; span=(0, 21), match='__version__ = "1.0.0"'> +283.25us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:cli 'publish: retry=' False +669.75us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:history:logs 'evaluate_version_bump("1.0.0", "None")' +0.0us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:vcs_helpers 'Reference v1.0.0 does not exist, considering all log' +0.0us
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:history:logs 'ignored' UnknownCommitMessageStyleError('Unable to parse the given commit message: Provide new directory option to actions\n') +9.4ms
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:history 'get_new_version("1.0.0", "None")' +9.7ms
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:vcs_helpers 'get_repository_owner_and_name' <re.Match object; span=(18, 55), match='/somerepo/my-project-name'> +10.1ms
    Fri, 14 Feb 2020 14:35:58 GMT semantic_release:cli 'branch=' 'master' +10.6ms
    Cmd('git') failed due to: exit code(1)
      cmdline: git checkout master
      stderr: 'error: pathspec 'master' did not match any file(s) known to git'
    ##[error]Docker run failed with exit code 1

    Not sure why it is trying to checkout master branch if I am trying to set it on some experimental branch.

    Nevermind, was missing the branch option at my setup.cfg. Now the version failed to publish but
    I assume it is due to the commit message not following the convention, right?

  17. danth commented on Feb 14, 2020

    @danth
    Contributor

    @KingDarBoja Yeah, if the commit message doesn't follow the convention then no new version will be published.

    Since I've merged the changes into master now, you'll need to update the action's branch in your workflow file for it to continue working.

  18. KingDarBoja commented on Feb 14, 2020

    @KingDarBoja
    Contributor

    @AlphaMycelium Makes sense, I just tried it again and the UnknownCommitMessageStyleError got away but still no new version being published.

    At some point, the debug log shows something like:
    Reference v1.0.0 does not exist, considering all log

    🤔

    OFF-TOPIC

    I saw at your example, you provide something like this at you setup.cfg:

    [semantic_release]
    version_variable=paa/__init__.py:__version__
    version_source=tag
    

    But the __version__ isn't there, that's on purpose? What about the setup.py file without specifying the version=version value?

  19. danth commented on Feb 14, 2020

    @danth
    Contributor

    @KingDarBoja I'm using setuptools-scm to get the version from Git tags instead of explicitly defining it in setup.py and __init__.py. This is to avoid having a commit created every time a new release is published. That's why I also set version_source=tag.

    I only include version_variable in setup.cfg because semantic release was throwing errors if I didn't, as far as I know it's never actually used.

  20. KingDarBoja commented on Feb 14, 2020

    @KingDarBoja
    Contributor

    Looks like the error is coming from get_commit_log() function at vsc_helperts but not sure why!

    Thinking on opening a new issue for this case.

  21. danth commented on Feb 14, 2020

    @danth
    Contributor

    @KingDarBoja It looks like it's trying to find commits which occur after the v1.0.0 tag, but that doesn't exist, so it looks at the entire commit history instead.

  22. KingDarBoja commented on Feb 14, 2020

    @KingDarBoja
    Contributor

    I am using the version_source as commit instead of tag and set commit_version_number=true. Maybe it is the reason it doesn't work? 🤔

    EDIT After looking at the source code, it works!

    image

    The key was indeed the commit history, as the source code defines the bump levels as the following:

    MINOR_TYPES = [
        'feat',
    ]
    
    PATCH_TYPES = [
        'fix',
        'perf',
    ]

    So just pushed a single commit with the key fix to trigger the bump level to 1.

    Thank you!

  23. danth commented on Feb 14, 2020

    @danth
    Contributor

    One problem I'm having is that the release notes are replaced with a short message containing only the name of the tag, as seen here.

    Since KingDarBoja's release notes are working, I think the problem I'm having with them is something specific to my own setup and not caused by GitHub Actions.

    @KingDarBoja For reference, are you using the preset GITHUB_TOKEN secret as shown in my example configuration, or a separate personal access token?

  24. KingDarBoja commented on Feb 14, 2020

    @KingDarBoja
    Contributor

    @AlphaMycelium I use the same preset as the example. Maybe the behaviour doesn't work at all if you set version_source=tag instead of commit.

    I can't share too much about the project but below are the actions.yml file and my setup.cfg:

    custom-action.yml

    name: my test release
    
    on:
     push:
       branches:
         - experimental-branch
    
    jobs:
     release:
       name: some release name
       runs-on: ubuntu-latest
    
       steps:
         - name: Checkout repo
           uses: actions/checkout@v2
           with:
             ref: experimental-branch
    
         - name: Release Package Core
           uses: AlphaMycelium/psr-action@master
           with:
             directory: ./core
             github_token: ${{ secrets.GITHUB_TOKEN }}

    config.cfg

    [semantic_release]
    version_variable=subfoldercore/__init__.py:__version__
    version_source=commit
    commit_version_number=true
    upload_to_pypi=false
    branch=experimental-branch
    

    I don't use setuptools-scm if that helps.

  25. danth commented on Feb 14, 2020

    @danth
    Contributor

    @KingDarBoja Hmmm. I was just wondering if it was some sort of permissions thing with the automatically-generated token, but it can't be if you're using that too and it works.

  26. danth commented on Apr 13, 2020

    @danth
    Contributor

    This is now finished and implemented within the main repository (instead of the separate psr-action), see the documentation page for details on setting it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureA new feature or a feature requestneeds-docsDocumentation needs to be updated★★

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions