Skip to content

Commit

Permalink
fix: move hash to function
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Williams <m@technovangelist.com>
  • Loading branch information
technovangelist committed Oct 26, 2023
1 parent a3e8c22 commit b9e0cc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
23 changes: 6 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
compile:
strategy:
matrix:
target: [{target: x86_64-unknown-linux-gnu, file: linux/ollamamodelupdate}, {target: x86_64-pc-windows-msvc, file: windows/ollamamodelupdate.exe}, {target: x86_64-apple-darwin, file: macos-x86/ollamamodelupdate}, {target: aarch64-apple-darwin, file: macos-arm64/ollamamodelupdate}]
target: [{target: x86_64-unknown-linux-gnu, file: linux-ollamamodelupdate}, {target: x86_64-pc-windows-msvc, file: win-ollamamodelupdate.exe}, {target: x86_64-apple-darwin, file: macos-x86-ollamamodelupdate}, {target: aarch64-apple-darwin, file: macos-arm64-ollamamodelupdate}]
runs-on: ubuntu-latest
needs: changelog
steps:
Expand All @@ -35,18 +35,7 @@ jobs:

- run:
deno compile --allow-net --target ${{ matrix.target.target }} --output ${{ matrix.target.file}} update.ts

# - uses: "marvinpinto/action-automatic-releases@latest"
# with:
# repo_token: "${{ secrets.GITHUB_TOKEN }}"
# automatic_release_tag: "latest"
# prerelease: false
# title: "Latest Build"
# files: |
# linux/ollamamodelupdate
# windows/ollamamodelupdate.exe
# macos-x86/ollamamodelupdate
# macos-arm64/ollamamodelupdate

- name: Release
uses: softprops/action-gh-release@v1
if: ${{ needs.changelog.outputs.skipped == 'false' }}
Expand All @@ -55,9 +44,9 @@ jobs:
name: ${{ needs.changelog.outputs.tag }}
body: ${{ needs.changelog.outputs.output }}
files: |
linux/ollamamodelupdate
windows/ollamamodelupdate.exe
macos-x86/ollamamodelupdate
macos-arm64/ollamamodelupdate
linux-ollamamodelupdate
win-ollamamodelupdate.exe
macos-x86-ollamamodelupdate
macos-arm64-ollamamodelupdate
token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 15 additions & 6 deletions update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ for await (const model of localModels) {
"Accept": "application/vnd.docker.distribution.manifest.v2+json"
}
})

if (remoteModelInfo.status == 200) {
const remoteModelInfoJSON = await remoteModelInfo.json()
const jsonstring = JSON.stringify(remoteModelInfoJSON).replace(/\s+/g, '')
const messageBuffer = new TextEncoder().encode(jsonstring);
const hashBuffer = await crypto.subtle.digest("SHA-256", messageBuffer);
const hash = encodeHex(hashBuffer);
// const jsonstring = JSON.stringify(remoteModelInfoJSON).replace(/\s+/g, '')
// const messageBuffer = new TextEncoder().encode(jsonstring);
// const hashBuffer = await crypto.subtle.digest("SHA-256", messageBuffer);
// const hash = encodeHex(hashBuffer);
const hash = await jsonhash(remoteModelInfoJSON);
if (hash === localdigest) {
console.log(`You have the latest ${model.name}`)
} else {
Expand All @@ -38,10 +40,17 @@ for await (const model of localModels) {
} catch (error) {
console.log(error)
}

})

}
}

}

async function jsonhash(json: string) {
const jsonstring = JSON.stringify(json).replace(/\s+/g, '')
const messageBuffer = new TextEncoder().encode(jsonstring);
const hashBuffer = await crypto.subtle.digest("SHA-256", messageBuffer);
const hash = encodeHex(hashBuffer);

return hash
}

0 comments on commit b9e0cc0

Please sign in to comment.