-
Notifications
You must be signed in to change notification settings - Fork 1
Ushcode/4/Update-workflows-for-CICD #5
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
base: main
Are you sure you want to change the base?
Changes from all commits
b906480
9e9bf47
2382f38
effb413
9621dd2
5971a50
b8233da
4fd720a
2dda161
f323fcf
f6d6f07
40e2e12
622ed86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/bin/bash | ||
|
|
||
| VERSION=$(cat -s "VERSION" 2>/dev/null) | ||
| MAIN_VERSION=$(curl -s "https://raw.githubusercontent.com/TheWorldAvatar/viz/main/VERSION") | ||
|
|
||
| if [ "$VERSION" == "" ]; then | ||
| echo -e "\e[31mError\e[0m: VERSION file is empty. Please ensure the correct version number is written here. Version currently on main is: $MAIN_VERSION" | ||
| exit 1 | ||
| fi | ||
| echo "Version set in this PR: $VERSION" | ||
| echo "Version on main: $MAIN_VERSION" | ||
|
|
||
| # Get the VERSION file from the main branch of the repo, check that this new version is updated ie does not match | ||
| if [ "$VERSION" == "$MAIN_VERSION" ]; then | ||
| echo -e "\e[31mError\e[0m: VERSION specified on this branch matches that on main. Update the VERSION file before merging." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check that there's no -SNAPSHOT qualifier | ||
| TOKEN="-SNAPSHOT" | ||
| if [[ "$VERSION" == *"$TOKEN"* ]]; then | ||
| echo -e "\e[31mError\e[0m: Remove the \"-SNAPSHOT\" qualifier in VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check that the change log contains an entry for the updated versions | ||
| CHANGELOG="CHANGELOG.md" | ||
| TOKEN="# $VERSION" | ||
| if ! grep -q "$TOKEN" "$CHANGELOG"; then | ||
| echo -e "\e[31mError\e[0m: Could not find corresponding entry for release $VERSION in CHANGELOG.md" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Update version in code/pom.xml | ||
| POM_XML="code/pom.xml" | ||
| if [ -f "$POM_XML" ]; then | ||
| sed -i -E "s|<version>[0-9]+\.[0-9]+\.[0-9]+</version>|<version>$VERSION</version>|" "$POM_XML" | ||
| echo "Updated version in $POM_XML to $VERSION" | ||
| else | ||
| echo -e "\e[31mError\e[0m: $POM_XML not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Update image version in docker-compose.yml | ||
| DOCKER_COMPOSE="docker-compose.yml" | ||
| if [ -f "$DOCKER_COMPOSE" ]; then | ||
| sed -i.bak -E "s|(image: .+:).+|\1$VERSION|" "$DOCKER_COMPOSE" && rm "$DOCKER_COMPOSE.bak" | ||
| echo "Updated image version in $DOCKER_COMPOSE to $VERSION" | ||
| else | ||
| echo -e "\e[31mError\e[0m: $DOCKER_COMPOSE not found" | ||
| exit 1 | ||
| fi | ||
|
Comment on lines
+44
to
+52
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this would be handled using a variable in the Docker compose file.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah probably better alright. I was thinking it was nice to see the changed file in PRs but probably pointless if compose file never changes otherwise |
||
|
|
||
| echo -e "\e[32mVersion incremented\e[0m, pom.xml and docker-compose.yml updated. Next step in this action will commit the changes" | ||
|
|
||
| exit 0 | ||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: Check Version | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - code/** | ||
|
|
||
| jobs: | ||
| check-version: | ||
| if: github.actor != 'dependabot[bot]' | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
|
|
||
| - name: Set up Git | ||
| run: | | ||
| git config --global user.email "viz-bot@noreply.theworldavatar.io" | ||
| git config --global user.name "twa-viz-bot" | ||
|
|
||
| - name: Check version incrementation | ||
| run: | | ||
| chmod +x .github/scripts/check-version.sh | ||
| .github/scripts/check-version.sh | ||
|
|
||
| - name: Save version to environment | ||
| run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV | ||
|
|
||
| - name: Check for changes | ||
| id: changes | ||
| run: | | ||
| git checkout ${{ github.head_ref }} | ||
| git add code/package.json docker-compose.yml | ||
| if ! git diff-index --quiet HEAD --; then | ||
| echo "::set-output name=changes::changes" | ||
| fi | ||
|
|
||
| - name: Push auto incremented version changes | ||
| if: steps.changes.outputs.changes == 'changes' | ||
| run: | | ||
| git commit -m "Update version to $VERSION in package.json and docker-compose.yml" | ||
| git push origin ${{ github.head_ref }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: Docker Image CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - code/** | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-and-push-image: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set version variables from file | ||
| id: read-version | ||
| run: | | ||
| VERSION=$(cat VERSION) | ||
| echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
| echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_ENV | ||
| echo "MINOR=$(echo $VERSION | cut -d. -f1).$(echo $VERSION | cut -d. -f2)" >> $GITHUB_ENV | ||
|
|
||
| # Set up Maven settings with GitHub token (currently needs one with access to packages on the old org. Will be replaced with the regular token when everything in same org) | ||
| - name: Set up Maven settings | ||
| run: | | ||
| mkdir -p ~/.m2 | ||
| echo "<settings><servers><server><id>github</id><username>${{ secrets.USHCODE_USERNAME }}</username><password>${{ secrets.USHCODE_PACKAGE_TOKEN }}</password></server></servers></settings>" > ~/.m2/settings.xml | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
Check warningCode scanning / CodeQL Unpinned tag for a non-immutable Action in workflow Medium
Unpinned 3rd party Action 'Docker Image CI' step
Uses Step Error loading related location Loading |
||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build docker image and push to ghcr | ||
| uses: docker/build-push-action@v6 | ||
Check warningCode scanning / CodeQL Unpinned tag for a non-immutable Action in workflow Medium
Unpinned 3rd party Action 'Docker Image CI' step
Uses Step Error loading related location Loading |
||
| with: | ||
| push: true | ||
| tags: | | ||
| ghcr.io/theworldavatar/feature-info-agent:latest | ||
| ghcr.io/theworldavatar/feature-info-agent:${{ env.VERSION }} | ||
| ghcr.io/theworldavatar/feature-info-agent:${{ env.MAJOR }} | ||
| ghcr.io/theworldavatar/feature-info-agent:${{ env.MINOR }} | ||
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 think this can be removed if we make use of the
mvnwscript(s) to read the version number from theVERSIONfile and then append-Drevision=$VERSIONonto themvncalls.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.
Okay cool I didn't actually look at your credo agent handling of this yet is that what you used there?