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 verified commits #163

Merged
merged 6 commits into from
Feb 19, 2022
Merged

Conversation

alvarezfr
Copy link
Contributor

Hi again @BetaHuhn!

I was playing around with the changes merged in #153 and I proposing this PR to solve a potential problem that I found:

Encoding

It's possible to cause encoding issues with my previous way of uploading the files/blobs to GitHub. I was using the API https://octokit.github.io/rest.js/v18#git-create-tree but passing the tree[].content to create the git tree structure on GitHub. I found that this way could be problematic because it treats all the files as if they were utf-8. I found problems in utf-16le for example but in some other cases.

I will explain the solution with comments in the PR.

Comment on lines +193 to +197
async getBlobBase64Content(file) {
const fileRelativePath = path.join(this.workingDir, file)
const fileContent = await fs.promises.readFile(fileRelativePath)

return fileContent.toString('base64')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of pushing the content of the file, this solution converts the file to base64.

Also, I have replaced the way of getting the content of the file. Previously I used the git show command, but I found that this could be problematic because of the exec command buffer size, and also the encoding that this command output produces.


const treeEntry = {
mode,
type,
content: await this.getBlobContent(sha),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't upload the content of the file when creating the tree, the files/blobs are references by its SHA only.

Comment on lines +261 to +286
async createGithubBlobs(commitSha) {
core.debug('Creating missing blobs on GitHub')
const [ previousTree, tree ] = await Promise.all([ this.getTree(`${ commitSha }~1`), this.getTree(commitSha) ])
const promisesGithubCreateBlobs = []

for (const treeEntry of tree) {
// If the current treeEntry are in the previous tree, that means that the blob is uploaded and it doesn't need to be uploaded to GitHub again.
if (previousTree.findIndex((entry) => entry.sha === treeEntry.sha) !== -1) {
continue
}

const base64Content = await this.getBlobBase64Content(treeEntry.path)

// Creates the blob. We don't need to store the response because the local sha is the same and we can use it to reference the blob
const githubCreateBlobRequest = this.github.git.createBlob({
owner: this.repo.user,
repo: this.repo.name,
content: base64Content,
encoding: 'base64'
})
promisesGithubCreateBlobs.push(githubCreateBlobRequest)
}

// Wait for all the file uploads to be completed
await Promise.all(promisesGithubCreateBlobs)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function compares the content of the tree to commit with the previous tree.

Iterates over each blob entry for the current commit checking if it was present on the previous tree. If it's not present, it uploads it to GitHub, if not just skip the upload.

@alvarezfr alvarezfr marked this pull request as ready for review February 9, 2022 22:49
Copy link
Owner

@BetaHuhn BetaHuhn 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, thanks!

@BetaHuhn BetaHuhn linked an issue Feb 19, 2022 that may be closed by this pull request
@BetaHuhn BetaHuhn changed the title Fix/verified commits 🐛 Fix verified commits Feb 19, 2022
@BetaHuhn BetaHuhn merged commit 0e2c893 into BetaHuhn:master Feb 19, 2022
@BetaHuhnBot
Copy link
Collaborator

🎉 This PR is included in version 1.17.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@alvarezfr alvarezfr deleted the fix/verified_commits branch September 1, 2023 11:50
@alvarezfr alvarezfr restored the fix/verified_commits branch September 1, 2023 11:50
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.

Action is pulling in binary files in a repo
3 participants