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

Manual bumping is broken #232

Closed
jonavos opened this issue Jan 3, 2023 · 13 comments
Closed

Manual bumping is broken #232

jonavos opened this issue Jan 3, 2023 · 13 comments

Comments

@jonavos
Copy link

jonavos commented Jan 3, 2023

The this commit has broken manual bumping.

This is because $GITHUB_BASE_REF is only set for PRs, otherwise it is empty. This means that ${default_branch} == "" which leads to evaluating history_type["full"]="$(git log ..HEAD --format=%B)" and therefore no full history to check for manual bumping tags.

A quick check suggests that $GITHUB_REF may be what was intended. See github actions environment variables. However I can't say if it will work in all cases, such as PRs.

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 4, 2023

Hey @jonavos can you paste an example of the manual bumping implementation workflow you are using?

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 4, 2023

I mean to fix it I need to understand what approach are you taking for merging your code and #bumps if your are not using PRs. using full should print the entire history, please share the run logs in debug mode

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 4, 2023

Alternatively if the default_branch is not being detected because of non PR use you can set the default branch as env var

env:
   DEFAULT_BRANCH: thedefaultbranchname

That should get the history.

But also we can add some extra checks if $GITHUB_BASE_REF is empty or null to report to the user to define the var DEFAULT_BRANCH

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 4, 2023

cc @sammcj as fyi

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 4, 2023

#235

@jonavos
Copy link
Author

jonavos commented Jan 4, 2023

Thanks for looking into this.

We bump the patch version automatically every main branch build, unless the PR has a #bump in the title, when we're hoping to bump the minor or the major version. We're merging in PRs using squash commits.

Here is the output from the build that didn't get minor bumped when expected. (I've clipped some text for confidentially reasons.)

/usr/bin/docker run --name e4a665560542388a4419352ba5d0e7_1ef39c --label 290506 --workdir /github/workspace --rm -e "CI" -e "TASK_VERSION" -e "GITHUB_TOKEN" -e "WITH_V" -e "DEFAULT_BUMP" -e "RELEASE_BRANCHES" -e "VERBOSE" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/Hexapa/Hexapa":"/github/workspace" 290506:79e4a665560542388a4419352ba5d0e7
++ git rev-parse --abbrev-ref HEAD
+ current_branch=main
+ pre_release=false
+ IFS=,
+ read -ra branch
+ for b in "${branch[@]}"
+ [[ main == \m\a\i\n ]]
+ pre_release=false
+ '[' main '!=' main ']'
+ echo 'pre_release = false'
+ git fetch --tags
*** CONFIGURATION ***
	DEFAULT_BUMP: patch
	DEFAULT_BRANCH: 
	WITH_V: true
	RELEASE_BRANCHES: main
	CUSTOM_TAG: 
	SOURCE: .
	DRY_RUN: false
	INITIAL_VERSION: 0.0.0
	TAG_CONTEXT: repo
	PRERELEASE: false
	PRERELEASE_SUFFIX: beta
	VERBOSE: true
	MAJOR_STRING_TOKEN: #major
	MINOR_STRING_TOKEN: #minor
	PATCH_STRING_TOKEN: #patch
	NONE_STRING_TOKEN: #none
	BRANCH_HISTORY: full
pre_release = false
+ tagFmt='^v?[0-9]+\.[0-9]+\.[0-9]+$'
+ preTagFmt='^v?[0-9]+\.[0-9]+\.[0-9]+(-beta\.[0-9]+)$'
+ case "$tag_context" in
++ git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)'
++ head -n 1
++ grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$'
+ tag=v0.2.19
++ git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)'
++ head -n 1
++ grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+(-beta\.[0-9]+)$'
+ pre_tag=
+ '[' -z v0.2.19 ']'
++ git rev-list -n 1 v0.2.19
+ tag_commit=f7a01d155e5a471ccfca551b3c72bec070e661ec
++ git rev-parse HEAD
+ commit=4485b2b516f22356fd60172dae627fb82b241da1
+ '[' f7a01d155e5a471ccfca551b3c72bec070e661ec == 4485b2b516f22356fd60172dae627fb82b241da1 ']'
++ git show -s --format=%B
++ git log ..HEAD --format=%B
+ history_type=(['last']='#minor Remove upgrade policy setting (#102)

* Remove upgrade policy setting

* Improve Android testing with robolectric

* Fix test build' ['full']='')
+ declare -A history_type
+ log=
+ printf 'History:\n---\n%s\n---\n' ''
+ case "$log" in
+ '[' patch == none ']'
History:
---

---
++ semver -i patch v0.2.19
+ new=0.2.20
+ part=patch
+ false
+ true
+ new=v0.2.20
+ echo -e 'Bumping tag v0.2.19 - New tag v0.2.20'
Bumping tag v0.2.19 - New tag v0.2.20
+ '[' -n '' ']'
+ setOutput new_tag v0.2.20
+ echo new_tag=v0.2.20
+ setOutput part patch
+ echo part=patch
+ setOutput tag v0.2.20
+ echo tag=v0.2.20
+ setOutput old_tag v0.2.19
+ echo old_tag=v0.2.19
+ false
+ git tag v0.2.20
++ date +%Y-%m-%dT%H:%M:%SZ
+ dt=2023-01-03T13:54:26Z
+ full_name=avos-io/Hexapa
++ tr -d '"'
++ sed 's/{\/sha}//g'
++ jq .repository.git_refs_url /github/workflow/event.json
+ git_refs_url=https://api.github.com/repos/avos-io/Hexapa/git/refs
2023-01-03T13:54:26Z: **pushing tag v0.2.20 to repo avos-io/Hexapa
+ echo '2023-01-03T13:54:26Z: **pushing tag v0.2.20 to repo avos-io/Hexapa'
++ curl -s -X POST https://api.github.com/repos/avos-io/Hexapa/git/refs -H 'Authorization: token ***' -d @-
+ git_refs_response='{
  "ref": "refs/tags/v0.2.20",
  "node_id": "REF_kwDOHliE3rFyZWZzL3RhZ3MvdjAuMi4yMA",
  "url": "https://api.github.com/repos/avos-io/Hexapa/git/refs/tags/v0.2.20",
  "object": {
    "sha": "4485b2b516f22356fd60172dae627fb82b241da1",
    "type": "commit",
    "url": "https://api.github.com/repos/avos-io/Hexapa/git/commits/4485b2b516f22356fd60172dae627fb82b241da1"
  }
}'
++ echo '{
  "ref": "refs/tags/v0.2.20",
  "node_id": "REF_kwDOHliE3rFyZWZzL3RhZ3MvdjAuMi4yMA",
  "url": "https://api.github.com/repos/avos-io/Hexapa/git/refs/tags/v0.2.20",
  "object": {
    "sha": "4485b2b516f22356fd60172dae627fb82b241da1",
    "type": "commit",
    "url": "https://api.github.com/repos/avos-io/Hexapa/git/commits/4485b2b516f22356fd60172dae627fb82b241da1"
  }
}'
++ jq .ref++ tr 
-d '"'
+ git_ref_posted=refs/tags/v0.2.20
+ echo '::debug::{
  "ref": "refs/tags/v0.2.20",
  "node_id": "REF_kwDOHliE3rFyZWZzL3RhZ3MvdjAuMi4yMA",
  "url": "https://api.github.com/repos/avos-io/Hexapa/git/refs/tags/v0.2.20",
  "object": {
    "sha": "4485b2b516f22356fd60172dae627fb82b241da1",
    "type": "commit",
    "url": "https://api.github.com/repos/avos-io/Hexapa/git/commits/4485b2b516f22356fd60172dae627fb82b241da1"
  }
}'
+ '[' refs/tags/v0.2.20 = refs/tags/v0.2.20 ']'
+ exit 0
  "ref": "refs/tags/v0.2.20",
  "node_id": "REF_kwDOHliE3rFyZWZzL3RhZ3MvdjAuMi4yMA",
  "url": "https://api.github.com/repos/avos-io/Hexapa/git/refs/tags/v0.2.20",
  "object": {
    "sha": "4485b2b516f22356fd60172dae627fb82b241da1",
    "type": "commit",
    "url": "https://api.github.com/repos/avos-io/Hexapa/git/commits/4485b2b516f22356fd60172dae627fb82b241da1"
  }
}

And the workflow.yml:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0 # Mandatory to use the extract version from tag action

      - name: Bump version and push tag # to test this, use env: DRY_RUN: true
        if: github.ref == 'refs/heads/main'
        id: tag
        uses: anothrNick/github-tag-action@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          WITH_V: true
          DEFAULT_BUMP: patch
          RELEASE_BRANCHES: main
          VERBOSE: true

      - [...]

Let me know if you need any more info.

I will set DEFAULT_BRANCH: main for now however I think other users will also hit this.

Thanks again.

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 5, 2023

Can you try with version 1.58 and report back if the problem persists?

The problem is the empty default_branch in non PRs var addressed by pr #235

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 5, 2023

Thanks for passing the logs to confirm this.

@jonavos
Copy link
Author

jonavos commented Jan 5, 2023

Thanks for pushing that fix.

Unfortunately, the problem still persists with our workflow. This is because after the squash commit to main the action will run git log "${default_branch}"..HEAD --format=%B where default_branch == main and also HEAD == main, resulting in no log messages.

For now we can work around this by reverting to the old behaviour with BRANCH_HISTORY: last instead of the new default full.

However it would be better to do something like ["full"]="$(git log "${tag_commit}".."${commit}" --format=%B)" to look at all the logs between the last tag and the current commit.

Again, I don't know how that would play with your PR based workflow.

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 5, 2023

@sammcj if you have any ideas how to can increase the testing for prs vs non-prs

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 5, 2023

@jonavos what if we add an extra declare option as

["full_squash"]="$(git log "${tag_commit}".."${commit}" --format=%B)"

So is just another log method to support squash with full merge and we add it to the readme when default is last and the full options depends on the use case

Cc @sammcj

@sbe-arg
Copy link
Collaborator

sbe-arg commented Jan 5, 2023

@jonavos #237 @sammcj

@jonavos
Copy link
Author

jonavos commented Jan 6, 2023

@sbe-arg thank you.

We will move our workflows to BRANCH_HISTORY: compare as suggested.

@jonavos jonavos closed this as completed Jan 6, 2023
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

No branches or pull requests

2 participants