Adding push-repo-version-to-cs
This commit is contained in:
parent
c96873e772
commit
a4e36b29c8
53
.github/workflows/push-repo-version-to-cs.yml
vendored
Normal file
53
.github/workflows/push-repo-version-to-cs.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
name: Update Repo Version Workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
npm-push:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
permissions:
|
||||||
|
# Give the default GITHUB_TOKEN write permission to commit and push the
|
||||||
|
# added or changed files to the repository.
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- id: read-issue
|
||||||
|
name: Read the issue comment
|
||||||
|
run: |
|
||||||
|
ISSUE_COMMENT_STRING='${{ github.event.comment.body }}'
|
||||||
|
DOCKER_BASE=`echo $ISSUE_COMMENT_STRING | jq ".image"`
|
||||||
|
BUILD_ID=`echo $ISSUE_COMMENT_STRING | jq ".tag"`
|
||||||
|
echo "DOCKER_BASE=$DOCKER_BASE" >> "$GITHUB_OUTPUT";
|
||||||
|
echo "BUILD_ID=$BUILD_ID" >> "$GITHUB_OUTPUT";
|
||||||
|
|
||||||
|
- name: Print IMAGE and TAG
|
||||||
|
run: |
|
||||||
|
echo "BUILD_ID: ${{ steps.read-issue.outputs.BUILD_ID }}";
|
||||||
|
echo "DOCKER_BASE: ${{ steps.read-issue.outputs.DOCKER_BASE }}";
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: cs
|
||||||
|
- name: Checkout deploy-tools
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: gmetribin/deploy-tools
|
||||||
|
ref: main
|
||||||
|
path: deploy-tools
|
||||||
|
token: ${{ github.token }}
|
||||||
|
|
||||||
|
- name: Increment package version and push
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
|
run: |
|
||||||
|
BUILD_ID=${{ steps.read-issue.outputs.BUILD_ID }}
|
||||||
|
DOCKER_BASE=${{ steps.read-issue.outputs.DOCKER_BASE }}
|
||||||
|
REPOLIST=./github/repolist.txt
|
||||||
|
pwd; ls -al;
|
||||||
|
cd cs;
|
||||||
|
../deploy-tools/repo_to_cs.sh -m $DOCKER_BASE -r $REPOLIST
|
||||||
|
git push origin main
|
||||||
|
git push --tags origin main
|
||||||
2
.github/workflows/trigger-cs-update.yml
vendored
2
.github/workflows/trigger-cs-update.yml
vendored
@ -1,5 +1,7 @@
|
|||||||
name: Reusable container push workflow
|
name: Reusable container push workflow
|
||||||
|
|
||||||
|
#This workflow is called from the repo that contains the source code
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
|
|||||||
78
src/repo_to_cs.sh
Executable file
78
src/repo_to_cs.sh
Executable file
@ -0,0 +1,78 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
echo "usage: $0 [-m docker_image -t tag -r repolist] | [-h]"
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
local IMAGE=$1
|
||||||
|
local TAG=$2
|
||||||
|
local REPOLIST=$3
|
||||||
|
|
||||||
|
KUST_FILES_LINES=$(grep -e "$IMAGE\s" $REPOLIST)
|
||||||
|
if [ -z "$KUST_FILES_LINES" ]
|
||||||
|
then
|
||||||
|
echo "Nothing to update";
|
||||||
|
exit;
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r KUST_FILES_LINE; do
|
||||||
|
KUST_PATH=$(echo "$KUST_FILES_LINE" | tr -s " " | cut -d " " -f 2)
|
||||||
|
#Need to add $ after ${IMAGE} so partial names don't get matched. (Eg: z5-edge shoudln't match z5-edge-socket)
|
||||||
|
#In the kustomization file, the name "repo2.hub.gmetri.io/repo-name" might end with either a space OR and endline character. Handline both cases.
|
||||||
|
LINE_N1=$(grep -n -e "${IMAGE}$" -e "${IMAGE}\s" ${KUST_PATH} | cut -d ":" -f 1)
|
||||||
|
LINE_N2=$(expr "$LINE_N1" + "1")
|
||||||
|
|
||||||
|
#Replace repo verion in kustomization.yaml. -n is true only if the following argument is non empty
|
||||||
|
if [ -n "$LINE_N2" ]
|
||||||
|
then
|
||||||
|
echo "Replacement Op: sed -i -e \"${LINE_N2}s/newTag: .*/newTag: ${TAG}/\" \"$KUST_PATH\""
|
||||||
|
sed -i -e "${LINE_N2}s/newTag: .*/newTag: ${TAG}/" "$KUST_PATH"
|
||||||
|
|
||||||
|
git add $KUST_PATH;
|
||||||
|
fi
|
||||||
|
done <<< "$KUST_FILES_LINES"
|
||||||
|
|
||||||
|
VER=$(cat version)
|
||||||
|
NEW_VER=$(./drone/increment_semver.sh -p $VER)
|
||||||
|
echo "$NEW_VER" > version
|
||||||
|
CS_REPO_NAME=`node -p require\(\'./package.json\'\).name`
|
||||||
|
|
||||||
|
git add version
|
||||||
|
git commit -m "$NEW_VER: $IMAGE updated to $TAG [CI SKIP]"
|
||||||
|
git tag -a $NEW_VER -m "$NEW_VER: $IMAGE updated to $TAG [CI SKIP]"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
### Starts here
|
||||||
|
while [ "$1" != "" ]; do
|
||||||
|
case $1 in
|
||||||
|
-m | --image ) shift
|
||||||
|
IMAGE=$1
|
||||||
|
;;
|
||||||
|
-t | --tag ) shift
|
||||||
|
TAG=$1
|
||||||
|
;;
|
||||||
|
-r | --repolist ) shift
|
||||||
|
REPOLIST=$1
|
||||||
|
;;
|
||||||
|
-h | --help ) usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
* ) usage
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z $IMAGE || -z $TAG || -z $REPOLIST ]]
|
||||||
|
then
|
||||||
|
echo "Not enough arguments"
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
main "$IMAGE" "$TAG" "$REPOLIST"
|
||||||
Loading…
x
Reference in New Issue
Block a user