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

Fix error messages in check-release.sh #3799

Merged
merged 1 commit into from Jun 20, 2023

Conversation

vvv
Copy link
Contributor

@vvv vvv commented May 31, 2023

  • check_tag: Report file name correctly. Use named variables.
  • Introduce read_version helper function. Simplify the implementation.
  • Show meaningful error message if GITHUB_REF is not set or its format is incorrect.

@vvv vvv changed the title Fix error messages in .github/scripts/check-release.sh Fix the error message in check-release.sh May 31, 2023
@vvv vvv force-pushed the fix.check-release-script branch from d8d2cd0 to 2a903a0 Compare May 31, 2023 21:10
.github/scripts/check-release.sh Outdated Show resolved Hide resolved
.github/scripts/check-release.sh Show resolved Hide resolved
.github/scripts/check-release.sh Show resolved Hide resolved
.github/scripts/check-release.sh Show resolved Hide resolved
@curquiza curquiza added this to the v1.3.0 milestone Jun 1, 2023
@curquiza curquiza added the maintenance Issue about maintenance (CI, tests, refacto...) label Jun 1, 2023
Copy link
Member

@irevoire irevoire left a comment

Choose a reason for hiding this comment

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

Hey @vvv.
There are a lot of good ideas here, but it doesn’t work anymore. Try to run the script before and after your PR, and you’ll see.

On my computer here are the results;

irevoire@macbook-pro-4 ~/clean/MeiliSearch 🌱 % bash .github/scripts/check-release.sh
Error: the current tag does not match the version in Cargo.toml: found  - expected 1.2.0
Error: the current tag does not match the version in Cargo.toml: found Cargo.lock - expected 1.2.0
1 irevoire@macbook-pro-4 ~/clean/MeiliSearch 🍐 % gh pr checkout 3799
Switched to branch 'fix.check-release-script'
irevoire@macbook-pro-4 ~/clean/MeiliSearch 🍴 % bash .github/scripts/check-release.sh
.github/scripts/check-release.sh: line 7: $3: unbound variable

.github/scripts/check-release.sh Show resolved Hide resolved
@vvv
Copy link
Contributor Author

vvv commented Jun 1, 2023

Hey @irevoire,

Thanks for looking at the patch. (Also, nice shell prompt! 🧑🏼‍🌾 Pretty organic.)

irevoire@macbook-pro-4 ~/clean/MeiliSearch 🌱 % bash .github/scripts/check-release.sh
Error: the current tag does not match the version in Cargo.toml: found  - expected 1.2.0
Error: the current tag does not match the version in Cargo.toml: found Cargo.lock - expected 1.2.0
1 irevoire@macbook-pro-4 ~/clean/MeiliSearch 🍐 % gh pr checkout 3799
Switched to branch 'fix.check-release-script'
irevoire@macbook-pro-4 ~/clean/MeiliSearch 🍴 % bash .github/scripts/check-release.sh
.github/scripts/check-release.sh: line 7: $3: unbound variable

check-release.sh is supposed to run in CI environment, where GITHUB_REF variable is set.

When you ran the script on your laptop, GITHUB_REF variable wasn't set, so current_tag got evaluated to an empty string.

current_tag=${GITHUB_REF#'refs/tags/v'}

file_tag="$(cat Cargo.toml | read_version)"
check_tag $current_tag $file_tag Cargo.toml || ret=1

check_tag command doesn't recognize unquoted empty string as a separate argument due to the way parameter expansion works in bash. check_tag sees only 2 arguments instead of 3 and complains:

❯ bash .github/scripts/check-release.sh || echo FAIL $?
.github/scripts/check-release.sh: line 7: $3: unbound variable
FAIL 1

When CI runs the script, GITHUB_REF is set to a string that (supposedly) starts with refs/tags/ prefix. In this case the script performs its duties properly:

# Happy case
❯ GITHUB_REF=refs/tags/v1.2.0 bash .github/scripts/check-release.sh || echo FAIL $?
OK

# Wrong tag
❯ GITHUB_REF=refs/tags/v8.8.8 bash .github/scripts/check-release.sh
Error: the current tag does not match the version in Cargo.toml: found 1.2.0, expected 8.8.8
Error: the current tag does not match the version in Cargo.lock: found 1.2.0, expected 8.8.8

# Invalid tag
❯ GITHUB_REF=refs/tags/bad-tag bash .github/scripts/check-release.sh
Error: the current tag does not match the version in Cargo.toml: found 1.2.0, expected refs/tags/bad-tag
Error: the current tag does not match the version in Cargo.lock: found 1.2.0, expected refs/tags/bad-tag

# Not a tag
❯ GITHUB_REF=refs/heads/main bash .github/scripts/check-release.sh
Error: the current tag does not match the version in Cargo.toml: found 1.2.0, expected refs/heads/main
Error: the current tag does not match the version in Cargo.lock: found 1.2.0, expected refs/heads/main

Still, the UX is bad. Let me improve error reporting...

@vvv vvv force-pushed the fix.check-release-script branch from 2a903a0 to 5dab6ea Compare June 1, 2023 18:05
@vvv vvv changed the title Fix the error message in check-release.sh Fix error messages in check-release.sh Jun 1, 2023
@vvv vvv requested a review from irevoire June 1, 2023 18:06
@curquiza
Copy link
Member

Hello @vvv
Sorry for the delay, but @irevoire is sick and I rely on his review. So, merging PR can takes time but we don't forget you!

@vvv
Copy link
Contributor Author

vvv commented Jun 12, 2023

Sorry for the delay, but @irevoire is sick and I rely on his review. So, merging PR can takes time but we don't forget you!

@curquiza Sure, no worries Thanks for reaching out to me. 😊

@irevoire Get well soon!

irevoire
irevoire previously approved these changes Jun 19, 2023
Copy link
Member

@irevoire irevoire left a comment

Choose a reason for hiding this comment

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

That looks good to me. @curquiza I don’t know how to test it on our CI though 😬

@vvv

This comment was marked as off-topic.

@vvv

This comment was marked as off-topic.

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

Hello

Thanks for your PR @vvv

Th change you made for the current script does not work as expected.

Our tags start with v, and if I try to do the following commands, I have an error:

bash-3.2$ export GITHUB_REF=v1.2.0
bash-3.2$ bash .github/scripts/check-release.sh
Error: GITHUB_REF is not a valid tag: v1.2.0

@vvv
Copy link
Contributor Author

vvv commented Jun 20, 2023

@curquiza GitHub adds refs/tags/ prefix to the value of GITHUB_REF.

❯ GITHUB_REF=refs/tags/v1.2.0 bash .github/scripts/check-release.sh
OK

See https://docs.github.com/en/actions/learn-github-actions/variables :

The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>.

@vvv
Copy link
Contributor Author

vvv commented Jun 20, 2023

vvv dismissed irevoire’s stale review via 685422a

I didn't mean to dismiss the review. I guess the repository is configured to auto-dismiss the review once the PR's branch is updated.

If both required reviews and stale review dismissal are enabled and a code-modifying commit is pushed to the branch of an approved pull request, the approval is dismissed. The pull request must be reviewed and approved again before it can be merged.

@curquiza
Copy link
Member

I didn't mean to dismiss the review. I guess the repository is configured to auto-dismiss the review once the PR's branch is updated.

Yes don't worry I know 😄

@curquiza GitHub adds refs/tags/ prefix to the value of GITHUB_REF.

Oh sorry @vvv, my bad, the worst part is I read what you wrote last week 🙈 I'm not a morning person definitely

@vvv
Can you remove your last commit? It's not useful for us to add this permission, I really want to avoid useless changes in the repository 😊 We will add it if we need it

- `check_tag`: Report file name correctly. Use named variables.
- Introduce `read_version` helper function. Simplify the implementation.
- Show meaningful error message if `GITHUB_REF` is not set or its format
  is incorrect.
@vvv vvv force-pushed the fix.check-release-script branch from 685422a to cfed349 Compare June 20, 2023 10:58
@vvv
Copy link
Contributor Author

vvv commented Jun 20, 2023

@curquiza Sure. I've removed the chmod +x commit and rebased the branch onto the latest master.

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

thank you @vvv 🙏 for your work, reactivity and involvement

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Jun 20, 2023

Build succeeded:

@vvv vvv closed this Jun 20, 2023
@meili-bors meili-bors bot merged commit 28404d5 into meilisearch:main Jun 20, 2023
2 checks passed
@vvv vvv deleted the fix.check-release-script branch June 20, 2023 16:11
@meili-bot meili-bot added the v1.3.0 PRs/issues solved in v1.3.0 released on 2023-07-31 label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Issue about maintenance (CI, tests, refacto...) v1.3.0 PRs/issues solved in v1.3.0 released on 2023-07-31
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants