git add metadata ; git commit -m"New image available" ; git push
Két probléma is adódott:
- Egyfelől nagyon ronda, persze működik, és a Jenkins-nek is megvan a joga írni a tárolót, de én valami kifinomultabb megoldásra vágytam.
- Másfelől pedig maga a sütés egy másik git tárolóból indul ki, szóval vagy valami ideiglenes könyvtárba dolgozok (/tmp, ram disk), aminek az életciklusát kezelni kell, vagy a git tárolóban a git tároló problémájával küzdök, és kényesen ügyelek rá, hogy mindkét tárolóba csak az oda illő dolgok kerüljenek be.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
: ${1?=File name is required} | |
file_name=$1 | |
GITHUB_ORG=mhmxs | |
GITHUB_REPO=test-metadata | |
GITHUB_USER=mhmxs | |
GITHUB_API_KEY=0ea72b***************** | |
GITHUB_REPO_URL=https://github.com/$GITHUB_ORG/$GITHUB_REPO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
head=$(curl -sf -u $GITHUB_USER:$GITHUB_API_KEY https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/git/refs/heads/master) | |
commitSha=$(echo $head | jq -r .object.sha) | |
commitUrl=$(echo $head | jq -r .object.url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
treeSha=$(echo $commit | jq -r .tree.sha) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blob=$(curl -sf -u $GITHUB_USER:$GITHUB_API_KEY -X POST https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/git/blobs -d "{\"content\":\"$(base64 $file_name)\",\"encoding\":\"base64\"}") | |
blobSha=$(echo $blob | jq -r .sha) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newTree=$(curl -sf -u $GITHUB_USER:$GITHUB_API_KEY -X POST https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/git/trees -d \ | |
"{\"base_tree\":\"$treeSha\",\"tree\":[{\"path\":\"$file_name\",\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"$blobSha\"}]}") | |
newTreeSha=$(echo $newTree | jq -r .sha) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newCommit=$(curl -sf -u $GITHUB_USER:$GITHUB_API_KEY -X POST https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/git/commits -d \ | |
"{\"message\":\"Upload $file_name\",\"parents\":[\"$commitSha\"],\"tree\":\"$newTreeSha\"}") | |
newCommitSha=$(echo $newCommit | jq -r .sha) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -s -u $GITHUB_USER:$GITHUB_API_KEY -X PATCH https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/git/refs/heads/master -d "{\"sha\":\"$newCommitSha\",\"force\":true}" | |
exit 0 |