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

Autobuild: Cleanup analyze_git_references.py #2471

Merged

Conversation

hoffie
Copy link
Member

@hoffie hoffie commented Mar 8, 2022

Short description of changes

This PR refactors .github/actions_scripts/analyze_git_references.py. It drops unused variables and logic, it replaces comments by (hopefully) well-named functions and fixes multiple coding style issues. It also adds a check to fail if we push release tags without proper Jamulus.pro VERSION.

Most of the changes are internal to the script and are not supposed to show a change in behavior from the outside.
Some of the changes do have an effect on the output though, which can be seen in the following output variable cleanups:

  • The following variable is not referenced in the Autobuild workflow at all and can therefore be safely dropped from the script output: PUSHED_NAME

  • The following variables are referenced in the Autobuild workflow and are declared as outputs, but those outputs are not referred to anywhere. Therefore, they can safely be dropped:

    • PUSHED_NAME
    • X_GITHUB_WORKSPACE
  • The following variables are only relevant for releases (PUBLISH_TO_RELEASE=true). Therefore, we only need to calculate their value for actual releases:

    • RELEASE_TITLE
    • RELEASE_TAG
    • IS_PRERELEASE

As I suspect this PR diff is rather hard to read, I'm providing output diffs (before/after this PR, last updated 2022-03-09 11:40 CEST) for the most relevant scenarios as proof that those cases still look sane:

Simulated push to a branch:

$ git status
On branch master
$ export GITHUB_WORKSPACE=. GITHUB_REF=refs/heads/somebranch; diff -u <(./.github/actions_scripts/analyse_git_reference.py | grep ::set | sort ) <(./.github/actions_scripts/analyse_git_reference_new.py | grep ::set | sort ) | grep ::set
-::set-output name=IS_PRERELEASE::true
-::set-output name=JAMULUS_VERSION::3.8.2dev-f5434765
 ::set-output name=PUBLISH_TO_RELEASE::false
-::set-output name=PUSHED_NAME::somebranch
-::set-output name=RELEASE_TAG::releasetag/somebranch
-::set-output name=RELEASE_TITLE::Pre-Release of "somebranch"
 ::set-output name=RELEASE_VERSION_NAME::3.8.2dev-f5434765
-::set-output name=X_GITHUB_WORKSPACE::.

Simulated push to a release tag:

$ git co r3_8_2
HEAD is now at 36cb9002 Update to version 3.8.2 for release
$ git status
HEAD detached at r3_8_2
$ export GITHUB_WORKSPACE=. GITHUB_REF=refs/tags/r3_8_2; diff -u <(./.github/actions_scripts/analyse_git_reference.py | grep ::set | sort ) <(./.github/actions_scripts/analyse_git_reference_new.py | grep ::set | sort ) | grep ::set
 ::set-output name=IS_PRERELEASE::false
-::set-output name=JAMULUS_VERSION::3.8.2
 ::set-output name=PUBLISH_TO_RELEASE::true
-::set-output name=PUSHED_NAME::r3_8_2
 ::set-output name=RELEASE_TAG::r3_8_2
 ::set-output name=RELEASE_TITLE::Release 3.8.2  (r3_8_2)
 ::set-output name=RELEASE_VERSION_NAME::3.8.2
-::set-output name=X_GITHUB_WORKSPACE::.

Simulated push to a pre-release tag:

$ git co r3_8_2rc1
HEAD is now at c4450193 Update version to 3.8.2rc1
$ git status
HEAD detached at r3_8_2rc1
$ export GITHUB_WORKSPACE=. GITHUB_REF=refs/tags/r3_8_2rc1; diff -u <(./.github/actions_scripts/analyse_git_reference.py | grep ::set | sort ) <(./.github/actions_scripts/analyse_git_reference_new.py | grep ::set | sort ) | grep ::set
 ::set-output name=IS_PRERELEASE::true
-::set-output name=JAMULUS_VERSION::3.8.2rc1
 ::set-output name=PUBLISH_TO_RELEASE::true
-::set-output name=PUSHED_NAME::r3_8_2rc1
 ::set-output name=RELEASE_TAG::r3_8_2rc1
 ::set-output name=RELEASE_TITLE::Release 3.8.2rc1  (r3_8_2rc1)
 ::set-output name=RELEASE_VERSION_NAME::3.8.2rc1
-::set-output name=X_GITHUB_WORKSPACE::.

Simulated push to a nightly tag:

$ git co r3_7_0devNightly1
HEAD is now at cae8d2d6 Prerelease r3_7_0devNightly1
$ git status
HEAD detached at r3_7_0devNightly1
$ export GITHUB_WORKSPACE=. GITHUB_REF=refs/tags/r3_7_0devNightly1; diff -u <(./.github/actions_scripts/analyse_git_reference.py | grep ::set | sort ) <(./.github/actions_scripts/analyse_git_reference_new.py | grep ::set | sort ) | grep ::set
 ::set-output name=IS_PRERELEASE::true
-::set-output name=JAMULUS_VERSION::3.7.0devNightly1-cae8d2d6
 ::set-output name=PUBLISH_TO_RELEASE::true
-::set-output name=PUSHED_NAME::r3_7_0devNightly1
 ::set-output name=RELEASE_TAG::r3_7_0devNightly1
 ::set-output name=RELEASE_TITLE::Release 3.7.0devNightly1-cae8d2d6  (r3_7_0devNightly1)
 ::set-output name=RELEASE_VERSION_NAME::3.7.0devNightly1-cae8d2d6
-::set-output name=X_GITHUB_WORKSPACE::.

Note: Releases which use other separators than _ will no longer be considered releases. This affects some nightly versions (r3.8.0devNightly1) which have been tagged differently than previously (r3_7_0devNightly1). I'd like to keep it like that as we should be consistent in our tags (although I'm not opposed to switching from rA_B_C to the more common vA.B.C, but that's out-of-scope for this PR.)

Simulated push to a non-version tag starting with r (is this case relevant?):

$ export GITHUB_WORKSPACE=. GITHUB_REF=refs/tags/rnon-release-tag-starting-with-r; diff -u <(./.github/actions_scripts/analyse_git_reference.py | grep ::set | sort ) <(./.github/actions_scripts/analyse_git_reference_new.py | grep ::set | sort ) | grep ::set
-::set-output name=IS_PRERELEASE::true
-::set-output name=JAMULUS_VERSION::3.8.2dev-f5434765
-::set-output name=PUBLISH_TO_RELEASE::true
-::set-output name=PUSHED_NAME::rnon-release-tag-starting-with-r
-::set-output name=RELEASE_TAG::rnon-release-tag-starting-with-r
-::set-output name=RELEASE_TITLE::Release 3.8.2dev-f5434765  (rnon-release-tag-starting-with-r)
+::set-output name=PUBLISH_TO_RELEASE::false
 ::set-output name=RELEASE_VERSION_NAME::3.8.2dev-f5434765
-::set-output name=X_GITHUB_WORKSPACE::.

Simulated push to a non-version tag not starting with r:

$ export GITHUB_WORKSPACE=. GITHUB_REF=refs/tags/non-release-tag; diff -u <(./.github/actions_scripts/analyse_git_reference.py | grep ::set | sort ) <(./.github/actions_scripts/analyse_git_reference_new.py | grep ::set | sort ) | grep ::set
-::set-output name=IS_PRERELEASE::true
-::set-output name=JAMULUS_VERSION::3.8.2dev-f5434765
 ::set-output name=PUBLISH_TO_RELEASE::false
-::set-output name=PUSHED_NAME::non-release-tag
-::set-output name=RELEASE_TAG::non-release-tag
-::set-output name=RELEASE_TITLE::Release 3.8.2dev-f5434765  (non-release-tag)
 ::set-output name=RELEASE_VERSION_NAME::3.8.2dev-f5434765
-::set-output name=X_GITHUB_WORKSPACE::.

CHANGELOG: Autobuild: Improved analyze_git_references.py script
(I'll likely merge all my Autobuild refactoring-related Changelog entries in the end)

Context: Fixes an issue?

Improves readability/maintenance.

Does this change need documentation? What needs to be documented and how?

No.

Status of this Pull Request

Ready for review.

What is missing until this pull request can be merged?

I'm still planning the following tests on my fork:

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

hoffie added 2 commits March 8, 2022 01:24
The following variable is not referenced in the Autobuild workflow at
all and can therefore be safely dropped from the script output:
PUSHED_NAME

The following variables are referenced in the Autobuild workflow and are
declared as outputs, but those outputs are not referred to anywhere.
Therefore, they can safely be dropped:
- PUSHED_NAME
- X_GITHUB_WORKSPACE

The following variables are only relevant for releases
(PUBLISH_TO_RELEASE=true):
- RELEASE_TITLE
- RELEASE_TAG
- IS_PRERELEASE

Therefore, we only need to calculate their value for actual releases.

This vastly simplifies the script logic.
@hoffie hoffie added this to the Release 3.9.0 milestone Mar 8, 2022
@ann0see
Copy link
Member

ann0see commented Mar 9, 2022

What happens if there is a tag without r* on a autobuild branch/non autobuild branch? I’m not sure if we wanted that to build (I‘m unsure if we even use non releatags anymore).

@hoffie
Copy link
Member Author

hoffie commented Mar 9, 2022

What happens if there is a tag without r*

I've added example output for that as well (all assuming that Jamulus.pro was not updated to match this pseudo-version).
Short answer: Auto build runs, no release will be created. I think that sounds reasonable?

on a autobuild branch/non autobuild branch?

There is no such distinction. A tag is not associated to a branch. It may (and often will) reference a commit which also happens to be on a branch, but that's not relevant for the logic here. What is relevant is the distinction of tags starting with r (but not matching A_B_C) vs. tags without a starting r. I've added both outputs above.

I’m not sure if we wanted that to build (I‘m unsure if we even use non releatags anymore).

I guess it could be adjusted, although I don't see what the downside of running a build is there?
As you say, I don't think we (jamulussoftware) use such tags, so it's not that relevant.

@hoffie
Copy link
Member Author

hoffie commented Mar 9, 2022

Short answer: Auto build runs, no release will be created.

Umm, that's not the complete truth.

  • rSOMETHING does create a pre-release. Although it has already been like that, I don't think it should. I'll check if it can be adjusted.
  • SOMETHING doesn't.

@hoffie hoffie force-pushed the autobuild-analyze_git_refs-cleanup branch from 32f4e09 to 4ced399 Compare March 9, 2022 10:06
hoffie added 2 commits March 9, 2022 11:09
Previously, a push to `rExample` would create a release (due to the tag
starting with `r`) while a push to `Example` would not.

We should only create (pre-)releases on pushes to
`r<Version><OptionalSuffixes>`. This commit ensures that.
@hoffie hoffie force-pushed the autobuild-analyze_git_refs-cleanup branch from 4ced399 to 24db7f5 Compare March 9, 2022 10:41
@hoffie
Copy link
Member Author

hoffie commented Mar 9, 2022

rSOMETHING does create a pre-release. Although it has already been like that, I don't think it should. I'll check if it can be adjusted.

Updated.

I've also added a test case for nightlies to the PR description (@ann0see please also note the comment about the tag format).

Copy link
Member

@softins softins left a comment

Choose a reason for hiding this comment

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

Looks good to me, and a lot tidier.

@@ -64,7 +64,7 @@ def set_github_variable(varname, varval):
release_version_name = get_release_version_name(jamulus_pro_version)

fullref = os.environ['GITHUB_REF']
publish_to_release = fullref.startswith('refs/tags/r')
publish_to_release = bool(re.match(r'^refs/tags/r\d+_\d+_\d+\S*$', fullref))
Copy link
Member

Choose a reason for hiding this comment

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

So we need to remember using _ instead of . everywhere on git.

(I'm not a fan of two different versions of describing the same version, but as far as I remember it is needed somehow).

Copy link
Member Author

Choose a reason for hiding this comment

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

So we need to remember using _ instead of . everywhere on git.

Yes.

(I'm not a fan of two different versions of describing the same version, but as far as I remember it is needed somehow).

Agreed. I'd be more happy if we were following the more common vA.B.C scheme. If we decide to go that route we should do that properly and adjust all places though. :)
It's just that I think it will cause some breakage (e.g. people checking out git tags have to adjust, scripts may have to be updated, etc.).
If you want to make it happen I suggest opening an issue... :)

Copy link
Member

@ann0see ann0see left a comment

Choose a reason for hiding this comment

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

I don’t know Python well, but I trust your tests (they should include the most commonly used features we need).

@hoffie hoffie merged commit 8f292fa into jamulussoftware:master Mar 9, 2022
@hoffie hoffie deleted the autobuild-analyze_git_refs-cleanup branch March 19, 2022 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants