-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
XML Version as File Modified time #431
Conversation
src/lib/upload-forms.js
Outdated
@@ -39,6 +39,7 @@ module.exports = async (projectDir, subDirectory, options) => { | |||
} | |||
|
|||
const xml = fs.read(xformPath); | |||
const xmlVersion = fs.statSync(filePath).mtime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure Git will preserve this correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it looks like it doesn't preserve it. Given this I think we should instead... when building the form in cht-conf, if the output is different than the previous version, store the current time somewhere in a source controlled file.
There are some challenges with this approach... for example
- If you repo is out of date then it may create a spurious version but spurious versions aren't the end of the world as long as everyone uses less-than and greater-than comparisons.
- If the system clock is out of date the version will jump around. This should be rare especially in a CICD setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are okay adding a Git library, then we could use the Git mod time,
$ git log -1 --pretty="format:%ci" test/data/lib/upload-forms/merge-properties/forms/example.xml
2020-04-14 21:54:42 +1200
e7a6711
to
df2fe7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks good, but maybe I am missing something with regards to the actual functionality. How does give us the ability to find the exact version of the xlsx file which generated the form (like Kenn mentioned in his initial description of the issue #395)? AFIK the GitHub hash search only works for commit
hashes and not hashes of the actual file contents
. I tried searching for the hash of the test form xml (hash:7e3bb121779a8e9f707b6e1db4c1b52aa6e875b5015b41b0a9115efa2d0de1d1
) but it did not give me anything useful.
@kennsippell Can you comment about the hash search? If we use Git Commit, it might be better because we could have a timestamp too. For my usage, I just need to know if the file changed. |
Is it important to search by hash? - Our old data science team had this problem pretty frequently - looking at data and wanting to map it back to the source. "This user answered How to do it
commit hash vs content hash - that's just my mistake. I think this comment from #395 is false. Even git's "pickaxe" doesn't seem to support searching by content hash. I suspect what you're hashing here can still be used to perform the search if somebody really wants to - just not through a convenient UI that I know of. Sorry to mislead. What you're doing here seems like a good option still. But note the approach of |
@aodhan-domhnaill @kennsippell Would it make sense to move this hashing code that we have here into |
Makes sense, but I'm not sure we are 100% on committing xml with xlsx changes. Currently with the xml being generated by the CI system, it isn't necessary. If we take this path - it'd be nice for the CI system to also forced the xml commit (either by committing it if different, or failing). |
@aodhan-domhnaill I have concerns about using the hash alone because I think it'll add significant complexity in the pipeline configuration because the hash won't be sequential. If a form is modified 100 times and a field was added in version 50, you would have to check the hash against all 50 later hashes to work out if the field should be there or not. Furthermore if version 101 was added it'd be easy to forget to update the if-else conditions and the configuration would regress. This would be much easier with a timestamp so the xml version can be compared with |
@garethbowen I would like a timestamp as well, but we can't use the Unix timestamp of the file. Using the timestamp off someones computer seems scary because timezones and local issues could cause a problem. Using the last Git commit for the file would be nice because that comes with a searchable hash and a timestamp. Alternatively, trusted timestamping is an option, but seems excessive. @kennsippell Will this tool always be run in a Git repo? Is using a Git commit hash/timestamp feasible? |
Timezones shouldn't be a problem as long as the timestamp is UTC. Local issues (such as computer clock out of sync) could be an issue but that shouldn't be common. I agree that trusted timestamps are overkill. We can't rely on the project using git or any change control at all, but we could try that and fall back to the local timestamp if necessary? |
0b16234
to
47cd304
Compare
@@ -52,6 +53,8 @@ describe('upload-forms', () => { | |||
const form = await api.db.get('form:example'); | |||
expect(form.type).to.equal('form'); | |||
expect(form.internalId).to.equal('different'); | |||
expect(form.xmlVersion.time).to.equal(123123); | |||
expect(form.xmlVersion.sha256).to.equal('7e3bb121779a8e9f707b6e1db4c1b52aa6e875b5015b41b0a9115efa2d0de1d1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth leaving a comment in here just to call out that if this assert fails (and you just made changes to the example.xml
), then this is expected behavior and you can just update the expected has value....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Description
#395
Code review items
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.