Skip to content

ci: fix test-migrations target when main branch is not present locally #13306

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

Merged
merged 1 commit into from
May 17, 2024

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented May 17, 2024

https://github.com/coder/coder/actions/runs/8989166240/job/24691648877 appears to have failed because the local reference to main was not present. Additionally, git rev-parse produces a slightly cryptic error message when the ref specified does not exit.

To validate this, I deleted the main branch locally and observed the same error before the change. After the change, this works as intended.

@johnstcn johnstcn self-assigned this May 17, 2024
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Additionally, git rev-parse produces a slightly cryptic error message when the ref specified does not exit.

I didn't notice any significant difference between the commands. 🤔

@@ -797,8 +797,11 @@ test-postgres: test-postgres-docker
test-migrations: test-postgres-docker
echo "--- test migrations"
set -euo pipefail
COMMIT_FROM=$(shell git rev-parse --short HEAD)
COMMIT_TO=$(shell git rev-parse --short main)
COMMIT_FROM=$(shell git log -1 --format='%h' HEAD)
Copy link
Member

Choose a reason for hiding this comment

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

Why short-form, btw? I guess it's more human friendly, but the long-form is more robust.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was initially worried about exceeding the maximum name length of a database name, but it looks like we're under the 63 byte limit even with the long identifier.

COMMIT_FROM=$(shell git rev-parse --short HEAD)
COMMIT_TO=$(shell git rev-parse --short main)
COMMIT_FROM=$(shell git log -1 --format='%h' HEAD)
echo "COMMIT_FROM=$${COMMIT_FROM}"
Copy link
Member

Choose a reason for hiding this comment

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

Pro-tip: declare is pretty nice (declare -p COMMIT_FROM COMMIT_TO. Not necessarily for here, but future reference.

@johnstcn
Copy link
Member Author

I didn't notice any significant difference between the commands. 🤔

I think it's way clearer:

$ git rev-parse --short foobar
fatal: Needed a single revision

$ git log -1 --format='%H' foobar
fatal: ambiguous argument 'foobar': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

I suppose we could also just read .git/refs/.

@johnstcn johnstcn merged commit f23d480 into main May 17, 2024
34 checks passed
@johnstcn johnstcn deleted the cj/fix-release-migrations branch May 17, 2024 09:24
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants