Skip to content

Replace UNIX specific script in build pipeline#292

Merged
pakb merged 2 commits intodevelopfrom
feat-replace-unix-specific-script
Nov 15, 2022
Merged

Replace UNIX specific script in build pipeline#292
pakb merged 2 commits intodevelopfrom
feat-replace-unix-specific-script

Conversation

@pakb
Copy link
Contributor

@pakb pakb commented Nov 15, 2022

so that the CI can still decipher which branch it is running on, and window users can still build the project

Test link

@pakb pakb requested a review from ltshb November 15, 2022 12:26
Copy link
Contributor

@ltshb ltshb left a comment

Choose a reason for hiding this comment

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

Good I would just keep more explicit names, the name should say what it actually contains.

*
* @return {String} The git branch without "origin/" or "refs/" portion
*/
function getGitBranchEvenWhenOnCI() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would simply call it getGitBranch. In comment above I would add a comment that this function retrieve the current matching git branch even if we are on a detached HEAD.

* @return {String} The git branch without "origin/" or "refs/" portion
*/
function getGitBranchEvenWhenOnCI() {
const gitShowRef = execSync('git show-ref --heads').toString().trim().split('\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

const headRefs = ...

*/
function getGitBranchEvenWhenOnCI() {
const gitShowRef = execSync('git show-ref --heads').toString().trim().split('\n')
const gitRevParseHead = execSync('git rev-parse HEAD').toString().trim()
Copy link
Contributor

Choose a reason for hiding this comment

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

const commitSha = ...

Copy link
Contributor

Choose a reason for hiding this comment

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

actually this could be passed as parameter as it is needed also below in line 40, to avoid calling it twice.

const gitRevParseHead = execSync('git rev-parse HEAD').toString().trim()
// we now do a grep-like operation, only keeping refs that have the hash found in gitRevParseHead
// we also have to remove all prefixes on the branch, i.e. /refs/tags or /origin/ etc...
const matchingRefsWithoutPrefix = gitShowRef
Copy link
Contributor

Choose a reason for hiding this comment

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

const branches = ...

@ltshb ltshb self-requested a review November 15, 2022 13:41
Copy link
Contributor

@ltshb ltshb left a comment

Choose a reason for hiding this comment

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

mmh an issue is when we retry a build, the info.json is not correct

{
  "version": "v0.1.0-beta.187-2-g37104fc",
  "build": {
    "date": "2022-11-15T13:32:37.060Z"
  },
  "git": {
    "hash": "37104fcc2c8be6337cc3689ee212cf491e1779ea",
    "dirty": false,
    "localChanges": ""
  }
}

See https://s3.console.aws.amazon.com/s3/object/build-artifacts-swisstopo?region=eu-central-1&prefix=dev/web-mapviewer/v0.1.0-beta.187-2-g37104fc/v0.1.0-beta.187-2-g37104fc/info.json and https://eu-central-1.console.aws.amazon.com/codesuite/codebuild/974517877189/projects/web-mapviewer/build/web-mapviewer%3Ad48a1d41-e674-4c2d-bbfd-be58fd1f26b9/?region=eu-central-1

@ltshb
Copy link
Contributor

ltshb commented Nov 15, 2022

An idea would be to pass the git branch as environment variable when built from he CI and keep the logic here only when no environment variable for the git branch is defined (when building locally). So the git branch logic on the CI would always be from the buildspec and we would not have two different logic, same as it is now for the version.

so that the CI can still decipher which branch it is running on, and window users can still build the project
@pakb pakb force-pushed the feat-replace-unix-specific-script branch from 37104fc to 0510274 Compare November 15, 2022 14:04
@pakb
Copy link
Contributor Author

pakb commented Nov 15, 2022

As discussed in our call, we will use the GIT_BRANCH env variable when defined (so on the CI) and resort to our node based code only when this variable is absent. The CI is too picky with this piece of code and fails for no apparent reasons sometimes...

Comment on lines +25 to +31
const currentHash = execSync('git rev-parse HEAD').toString().trim()

// We take the version from GIT_BRANCH but if not set, then take it from git show-ref
let gitBranch = process.env.GIT_BRANCH
if (!gitBranch) {
gitBranch = getGitBranch(currentHash)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it not make more sense to keep this code inside the async handler function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would make more sense, as if something would fail in this piece of code it would happen in post-build, and not at startup, I'll move the code inside

Copy link
Contributor

@ltshb ltshb left a comment

Choose a reason for hiding this comment

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

Looks all good

so that the build log is not polluted at startup by this, and if this part of the code fail (for some reasons) it is in post-build phase as it should be
@pakb pakb merged commit d8cc5af into develop Nov 15, 2022
@pakb pakb deleted the feat-replace-unix-specific-script branch November 15, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants