From b906480e5f08c6a25ef0c251cda3180b5b7f7a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 16:11:15 +0000 Subject: [PATCH 01/13] Update-workflows-for-CICD: tidy maven credentials script --- VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..0c89fc9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +4.0.0 \ No newline at end of file From 9e9bf475a72b4385c0d0cb992cce3e61d6f3e356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 16:12:51 +0000 Subject: [PATCH 02/13] Update-workflows-for-CICD: tidy maven credential script --- .github/scripts/set-maven-credentials.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/scripts/set-maven-credentials.sh b/.github/scripts/set-maven-credentials.sh index ba43e1d..ec08a8e 100644 --- a/.github/scripts/set-maven-credentials.sh +++ b/.github/scripts/set-maven-credentials.sh @@ -22,7 +22,6 @@ if [[ -z "${MAVEN_USERNAME}" ]]; then echo "ERROR: The environment variable 'MAVEN_USERNAME' has not been set." exit 1 else - MAVEN_USERNAME="${MAVEN_USERNAME}" echo "Retrieved the 'MAVEN_USERNAME' environment variable." fi @@ -31,17 +30,15 @@ if [[ -z "${MAVEN_PASSWORD}" ]]; then echo "ERROR: The environment variable 'MAVEN_PASSWORD' has not been set." exit 1 else - MAVEN_PASSWORD="${MAVEN_PASSWORD}" echo "Retrieved the 'MAVEN_PASSWORD' environment variable." fi - # Copy the template settings file to output location -cp ./template-maven-settings.xml $TARGET_DIR/settings.xml +cp ./template-maven-settings.xml "$TARGET_DIR"/settings.xml # Inject the maven credentials into new settings file -sed -i "s/REPO_USERNAME/$MAVEN_USERNAME/" $TARGET_DIR/settings.xml -sed -i "s/REPO_PASSWORD/$MAVEN_PASSWORD/" $TARGET_DIR/settings.xml +sed -i "s/REPO_USERNAME/$MAVEN_USERNAME/" "$TARGET_DIR"/settings.xml +sed -i "s/REPO_PASSWORD/$MAVEN_PASSWORD/" "$TARGET_DIR"/settings.xml # Finish echo "Script finished successfully, 'settings.xml' file can now be used." From 2382f3877dd1587250c19afadadf4049ac12f454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 16:21:14 +0000 Subject: [PATCH 03/13] add a test script --- .github/workflows/test.yml | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b9a04f2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,44 @@ +name: Test the Feature Info Agent + +on: + pull_request: + branches: + - main + paths: + - code/** + - "!**.md" + - "!**/release.html" + workflow_dispatch: + +jobs: + build-image: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # 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 "github${{ secrets.USHCODE_USERNAME }}${{ secrets.USHCODE_PACKAGE_TOKEN }}" > ~/.m2/settings.xml + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: "adopt" + java-version: "17" + + - name: Cache Maven dependencies + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + # Run Maven tests + - name: Run Tests + working-directory: code + run: mvn test From effb4138929fccf98286ff9e7cbebfdb5d058f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 16:23:42 +0000 Subject: [PATCH 04/13] replace release workflow with updated docker CI workflow --- .github/workflows/docker-ci.yml | 52 ++++++ .../workflows/feature-info-agent_release.yml | 149 ------------------ .github/workflows/feature-info-agent_test.yml | 60 ------- 3 files changed, 52 insertions(+), 209 deletions(-) create mode 100644 .github/workflows/docker-ci.yml delete mode 100644 .github/workflows/feature-info-agent_release.yml delete mode 100644 .github/workflows/feature-info-agent_test.yml diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml new file mode 100644 index 0000000..812ed30 --- /dev/null +++ b/.github/workflows/docker-ci.yml @@ -0,0 +1,52 @@ +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 + + - name: Set up Maven credentials + working-directory: ./Agents/FeatureInfoAgent/credentials + run: echo "$USERNAME" > repo_username.txt && echo "$PASSWORD" > repo_password.txt + env: + USERNAME: ${{github.actor}} + PASSWORD: ${{github.token}} + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + 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 + 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 }} diff --git a/.github/workflows/feature-info-agent_release.yml b/.github/workflows/feature-info-agent_release.yml deleted file mode 100644 index 0ec12a7..0000000 --- a/.github/workflows/feature-info-agent_release.yml +++ /dev/null @@ -1,149 +0,0 @@ -# -# This workflow contains a job that builds and pushes the Docker image -# for the FeatureInfoAgent, running its JUnit tests in the process. -# -# Note this workflow will use the automatically generated GITHUB_TOKEN -# and the username of the account that triggered it. -# -# Also note that the first time a Docker image is pushed by this workflow, -# it will be uploaded as a private image. You'll have to manually make -# it public using the controls on the GitHub website. -# -# Author: Michael Hillman (mdhillman<@>cmclinnovations.com) -# -name: Push the FeatureInfoAgent - - -# Trigger this workflow to run on the main branch -# after a push (i.e. a finished PR) and only if the -# agent's files have changed -on: - push: - branches: - - main - paths: - - Agents/FeatureInfoAgent/** - - '!**.md' - - '!**/release.html' - - -# Job definitions -jobs: - - # Single job to build and push the image - build-and-push-image: - - # Run on latest version of Ubuntu - runs-on: ubuntu-latest - - steps: - # Checkout the repository - - name: Checkout repository - uses: actions/checkout@v3 - - - # Write Maven credentials - - name: Set up Maven credentials - working-directory: ./Agents/FeatureInfoAgent/credentials - run: echo "$USERNAME" > repo_username.txt && echo "$PASSWORD" > repo_password.txt - env: - USERNAME: ${{github.actor}} - PASSWORD: ${{github.token}} - - - # Create & boot a builder using the default docker-container driver. - - name: Set up Docker build - uses: docker/setup-buildx-action@v2 - - - # Extracts the image tag from the compose file - - name: Extract image tag - id: extractor - uses: mikefarah/yq@master - with: - cmd: yq '.services.feature-info-agent.image' './Agents/FeatureInfoAgent/docker-compose.yml' - - - # Get and parse the version from the POM - - name: Parse the version number - working-directory: ./Agents/FeatureInfoAgent - run: | - sudo apt install -y libxml2-utils - VERSION=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" ./code/pom.xml) - echo versionFull=$VERSION >> $GITHUB_ENV - echo versionMajor=$(echo $VERSION | cut -d. -f1) >> $GITHUB_ENV - echo versionMinor=$(echo $VERSION | cut -d. -f1).$(echo $VERSION | cut -d. -f2) >> $GITHUB_ENV - - - # Login to Docker image registry - - name: Login to Docker registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{github.actor}} - password: ${{github.token}} - - - # Build and push the agent's Docker image - - name: Build and push image (inc. unit tests) - uses: docker/build-push-action@v3 - with: - push: true - context: ./Agents/FeatureInfoAgent - tags: | - ghcr.io/cambridge-cares/feature-info-agent:latest - ghcr.io/cambridge-cares/feature-info-agent:${{ env.versionFull }} - ghcr.io/cambridge-cares/feature-info-agent:${{ env.versionMajor }} - ghcr.io/cambridge-cares/feature-info-agent:${{ env.versionMinor }} - - - # Generate the release body text - - name: Generate release text - id: generate-text - working-directory: ./ - run: | - chmod +x ./.github/scripts/fia/make-release-body.sh - ./.github/scripts/fia/make-release-body.sh > $HOME/body.md - echo body=$HOME/body.md >> $GITHUB_ENV - - - # Make a release on the main branch - - name: Make release - uses: ncipollo/release-action@v1 - with: - name: "feature-info-agent-${{ env.versionFull }}" - tag: "feature-info-agent-${{ env.versionFull }}" - commit: "main" - bodyFile: "${{ env.body }}" - - - # Setup Python installation - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - # Generate the release email content - - name: Generate release email - id: generate-email - working-directory: ./ - run: | - pip install markdown - python ./.github/scripts/fia/make-release-email.py ${{ env.versionFull }} - echo email=$HOME/email.html >> $GITHUB_ENV - - - # Send a notification email - - name: Send email - uses: dawidd6/action-send-mail@v3 - with: - server_address: mail.cmclinnovations.com - server_port: 465 - secure: true - username: ${{secrets.CMCL_MAIL_USERNAME}} - password: ${{secrets.CMCL_MAIL_PASSWORD}} - subject: "New TWA release: FeatureInfoAgent ${{ env.versionFull }}" - to: cares-twa@lists.cam.ac.uk,all@cmcl.io - from: Automated TWA action - html_body: "file://${{ env.email }}" \ No newline at end of file diff --git a/.github/workflows/feature-info-agent_test.yml b/.github/workflows/feature-info-agent_test.yml deleted file mode 100644 index cf8ec7e..0000000 --- a/.github/workflows/feature-info-agent_test.yml +++ /dev/null @@ -1,60 +0,0 @@ -# -# This workflow contains a job that builds the Docker image for -# the FeatureInfoAgent, running its JUnit tests in the process. -# -# Note this workflow will use the automatically generated GITHUB_TOKEN -# and the username of the account that triggered it. -# -# Author: Michael Hillman (mdhillman<@>cmclinnovations.com) -# -name: Test the FeatureInfoAgent - - -# Trigger this workflow on pull requests to the main branch, -# but ONLY when files within the agent's directory are changed. -on: - pull_request: - branches: - - main - paths: - - Agents/FeatureInfoAgent/** - - '!**.md' - - '!**/release.html' - - -# Job definitions -jobs: - - # Single job to build the image - build-image: - - # Run on latest version of Ubuntu - runs-on: ubuntu-latest - - steps: - # Checkout the repository - - name: Checkout repository - uses: actions/checkout@v3 - - - # Write Maven credentials - - name: Set up Maven credentials - working-directory: ./Agents/FeatureInfoAgent/credentials - run: echo "$USERNAME" > repo_username.txt && echo "$PASSWORD" > repo_password.txt - env: - USERNAME: ${{github.actor}} - PASSWORD: ${{github.token}} - - - # Create & boot a builder using the default docker-container driver. - - name: Set up Docker build - uses: docker/setup-buildx-action@v2 - - - # Build the agent's Docker image - - name: Run unit tests (via Docker build) - uses: docker/build-push-action@v3 - with: - push: false - context: ./Agents/FeatureInfoAgent - \ No newline at end of file From 9621dd2310021fff9a31a45382ebc2b9f81bc1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 16:49:05 +0000 Subject: [PATCH 05/13] add version check and tag workflows --- .github/scripts/check-version.sh | 56 +++++++++++++++++++++++++++++ .github/workflows/check-version.yml | 52 +++++++++++++++++++++++++++ .github/workflows/tag-version.yml | 41 +++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100755 .github/scripts/check-version.sh create mode 100644 .github/workflows/check-version.yml create mode 100644 .github/workflows/tag-version.yml diff --git a/.github/scripts/check-version.sh b/.github/scripts/check-version.sh new file mode 100755 index 0000000..a606b58 --- /dev/null +++ b/.github/scripts/check-version.sh @@ -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|[0-9]+\.[0-9]+\.[0-9]+|$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 + +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 diff --git a/.github/workflows/check-version.yml b/.github/workflows/check-version.yml new file mode 100644 index 0000000..5a5d4bf --- /dev/null +++ b/.github/workflows/check-version.yml @@ -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 }} diff --git a/.github/workflows/tag-version.yml b/.github/workflows/tag-version.yml new file mode 100644 index 0000000..8c55f36 --- /dev/null +++ b/.github/workflows/tag-version.yml @@ -0,0 +1,41 @@ +name: Tag Version + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + tag-version: + runs-on: ubuntu-latest + + permissions: + contents: write + + env: + VERSION: + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Git + run: | + git config --global user.email "viz-bot@noreply.theworldavatar.io" + git config --global user.name "twa-viz-bot" + + - name: Save version to environment + run: | + if [ -f VERSION ]; then + echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV + else + echo "VERSION file not found" && exit 1 + fi + + - name: Create tag + run: | + git tag -a "v${{ env.VERSION }}" -m "Version ${{ env.VERSION }}" + git push origin "v${{ env.VERSION }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 5971a50e94ab4714f4a908305ab76cd05268a09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 16:49:29 +0000 Subject: [PATCH 06/13] remove email release python script --- .github/scripts/fia/make-release-body.sh | 29 ------------ .github/scripts/fia/make-release-email.py | 57 ----------------------- 2 files changed, 86 deletions(-) delete mode 100644 .github/scripts/fia/make-release-body.sh delete mode 100644 .github/scripts/fia/make-release-email.py diff --git a/.github/scripts/fia/make-release-body.sh b/.github/scripts/fia/make-release-body.sh deleted file mode 100644 index 15c0bc6..0000000 --- a/.github/scripts/fia/make-release-body.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# This script generates the body text for releases of the -# Feature Info Agent (FIA). -# -# Author: Michael Hillman (mdhillman<@>cmcl.io) - -CHANGELOG="./Agents/FeatureInfoAgent/CHANGELOG.md" -regexp="^#\s.*" -SECTION=0 - -BODY="This release package marks a release of the TWA FeatureInfoAgent (FIA), a intelligent agent/microservice for discovering metadata on visualised assets. Release notes for this version of the FIA can be found below, for more details, see the \`CHANGELOG.md\` and \`README.md\` files within the \`/Agents/FeatureInfoAgent/\` directory.\n\n" - -# Read changelog line by line -# Only store notes within the first header -while IFS= read -r line -do - if [[ $line =~ $regexp ]]; then - SECTION=$((SECTION + 1)) - fi - - if [[ $SECTION == 1 ]]; then - BODY="$BODY\n$line" - fi - -done < "$CHANGELOG" - -# Output final notes -echo -e "$BODY" \ No newline at end of file diff --git a/.github/scripts/fia/make-release-email.py b/.github/scripts/fia/make-release-email.py deleted file mode 100644 index 46aa10a..0000000 --- a/.github/scripts/fia/make-release-email.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# This script generates the HTML text for the email notification -# generated with a new version of the TWA FeatureInfoAgent -# (FIA) is released. -# -# Note that this script also expects Python to have been installed and setup -# to run the markdown2html.py script within thie directory. -# -# Author: Michael Hillman (mdhillman<@>cmcl.io) - -import os -import sys -import markdown - -# Read version tag from first argument -version = sys.argv[1] -print("Input version tag is " + version) - -# Read the top most section of the patch notes -notes = "" -with open('./Agents/FeatureInfoAgent/CHANGELOG.md', 'r') as f: - lines = f.readlines() - section = 0 - - for line in lines: - # Count the section - if line.startswith('# '): - section = section + 1 - - # Only gather section 1 - if section == 1: - notes = notes + "|" + line - -print("Have read change log file.") - -# Convert from markdown in to HTML -notes = markdown.markdown(notes.replace("|", "\n")) -print("Have converted change log to HTML.") - -# Read template email file -with open('./Agents/FeatureInfoAgent/docs/release.html', 'r') as f: - template = f.read() -print("Have read template email file.") - -# String substitutions -email = template.replace("[VERSION]", version) -email = email.replace("[NOTES]", notes) -print("Have made substitutions.") - -# Write to file -target = os.path.expanduser('~') -target = os.path.join(target, 'email.html') - -with open(target, 'w') as f: - f.write(email) -print("Have written out final email file.") \ No newline at end of file From b8233da83381ede10657a05c0ec20921545bfc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:02:19 +0000 Subject: [PATCH 07/13] set permissions in test flow --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b9a04f2..1fac2ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,13 +7,16 @@ on: paths: - code/** - "!**.md" - - "!**/release.html" workflow_dispatch: jobs: build-image: runs-on: ubuntu-latest + permissions: + contents: read + packages: read # will be needed later but using the secret for now + steps: - name: Checkout repository uses: actions/checkout@v4 From 4fd720ae3c4ff24d87ce3df69e35389b403b0820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:10:46 +0000 Subject: [PATCH 08/13] rm build.sh script in favour of VERSION file --- build.sh | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 build.sh diff --git a/build.sh b/build.sh deleted file mode 100644 index 8add532..0000000 --- a/build.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# -# Use this script to build the latest copy of the FeatureInfoAgent image for local use. -# -# Note that will build a local copy of a single image with the below tags, where -# VERSION is whatever is currently written in the project's pom.xml file. -# -# - ghcr.io/cambridge-cares/feature-info-agent:latest -# - ghcr.io/cambridge-cares/feature-info-agent:VERSION -# -# These should not be pushed to the GitHub image repository unless absolutely -# necessary. Automated actions will handle the release once a PR to main is merged. -# -# - -echo -echo "This script requires the 'xmllint' tool to parse the project's pom.xml" -echo "file and determine the current version number. Is it installed?" -echo -read -p "Is the 'xmllint' package installed (Y/N)? " -n 1 -r -echo -if [[ $REPLY =~ ^[Yy]$ ]] -then - # Read the version from the pom.xml file - VERSION="$(xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" ./code/pom.xml)" - echo "Discovered version as $VERSION" - - # Write env file for docker - echo "TAG=$VERSION" > .env - - # Build 'latest' tagged image - docker compose -f docker-compose.yml build - - # Add version specific tag - docker tag "ghcr.io/cambridge-cares/feature-info-agent:latest" "ghcr.io/cambridge-cares/feature-info-agent:$VERSION" -else - echo "Please run install the 'xmllint' package and try again." - exit 1 -fi \ No newline at end of file From 2dda16117120b6387e855af306344c2f25128fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:11:03 +0000 Subject: [PATCH 09/13] rm maven credentials github script in favour of repo secrets --- .github/scripts/set-maven-credentials.sh | 45 ------------------------ 1 file changed, 45 deletions(-) delete mode 100644 .github/scripts/set-maven-credentials.sh diff --git a/.github/scripts/set-maven-credentials.sh b/.github/scripts/set-maven-credentials.sh deleted file mode 100644 index ec08a8e..0000000 --- a/.github/scripts/set-maven-credentials.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# -# This script reads the "MAVEN_USERNAME" and "MAVEN_PASSWORD" environment variables, -# and uses the accompanying "template-maven-settings.xml" file to generate a new -# "settings.xml" file. This new file is then copied to the input directory so that -# it can be used when building Java projects that require access to TheWorldAvatar's -# package repository. -# -# Note: This script should be run from the directory it's contained within (at the -# time of writing, this is "/.github/scripts"). -# -# Author: Michael Hillman -# - -# Get first argument, should be location of output directory -TARGET_DIR=$1 -echo "Will write 'settings.xml' file to directory at $TARGET_DIR" - -# Get the MAVEN_USERNAME environment variable -if [[ -z "${MAVEN_USERNAME}" ]]; then - echo "ERROR: The environment variable 'MAVEN_USERNAME' has not been set." - exit 1 -else - echo "Retrieved the 'MAVEN_USERNAME' environment variable." -fi - -# Get the MAVEN_PASSWORD environment variable -if [[ -z "${MAVEN_PASSWORD}" ]]; then - echo "ERROR: The environment variable 'MAVEN_PASSWORD' has not been set." - exit 1 -else - echo "Retrieved the 'MAVEN_PASSWORD' environment variable." -fi - -# Copy the template settings file to output location -cp ./template-maven-settings.xml "$TARGET_DIR"/settings.xml - -# Inject the maven credentials into new settings file -sed -i "s/REPO_USERNAME/$MAVEN_USERNAME/" "$TARGET_DIR"/settings.xml -sed -i "s/REPO_PASSWORD/$MAVEN_PASSWORD/" "$TARGET_DIR"/settings.xml - -# Finish -echo "Script finished successfully, 'settings.xml' file can now be used." -exit 0 From f323fcfa00737307e6bdaf6a7e776ce9e238d8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:11:31 +0000 Subject: [PATCH 10/13] add maven secrets to docker ci scrip --- .github/workflows/docker-ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 812ed30..c3e0907 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -27,12 +27,11 @@ jobs: echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_ENV echo "MINOR=$(echo $VERSION | cut -d. -f1).$(echo $VERSION | cut -d. -f2)" >> $GITHUB_ENV - - name: Set up Maven credentials - working-directory: ./Agents/FeatureInfoAgent/credentials - run: echo "$USERNAME" > repo_username.txt && echo "$PASSWORD" > repo_password.txt - env: - USERNAME: ${{github.actor}} - PASSWORD: ${{github.token}} + # 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 "github${{ secrets.USHCODE_USERNAME }}${{ secrets.USHCODE_PACKAGE_TOKEN }}" > ~/.m2/settings.xml - name: Log in to GitHub Container Registry uses: docker/login-action@v3 From f6d6f077af81e5c4f26a2d97514a37f0f94cd14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:11:49 +0000 Subject: [PATCH 11/13] formatting in test.yml --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1fac2ad..8cead09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: packages: read # will be needed later but using the secret for now steps: - - name: Checkout repository + - name: Check Out Repository uses: actions/checkout@v4 # 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) @@ -41,7 +41,6 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - # Run Maven tests - name: Run Tests working-directory: code run: mvn test From 40e2e126a13f45c89f95c72984a201f187a48c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:21:29 +0000 Subject: [PATCH 12/13] rename credentials directory to maven-credentials for clarity --- Dockerfile | 2 +- {credentials => maven-credentials}/.gitignore | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {credentials => maven-credentials}/.gitignore (100%) diff --git a/Dockerfile b/Dockerfile index d347d8a..c35241b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ WORKDIR /root/.m2 # Note that | rather than / is used as the sed delimiter, since encrypted passwords can contain the latter, but not the former RUN sed -i "s|MASTER_PASSWORD|$(mvn --encrypt-master-password master_password)|" settings-security.xml -RUN sed -i "s|REPO_USERNAME|$(cat ../credentials/repo_username.txt)|;s|REPO_PASSWORD|$(cat ../credentials/repo_password.txt|xargs mvn --encrypt-password)|" settings.xml +RUN sed -i "s|REPO_USERNAME|$(cat ../maven-credentials/repo_username.txt)|;s|REPO_PASSWORD|$(cat ../maven-credentials/repo_password.txt|xargs mvn --encrypt-password)|" settings.xml # Build WORKDIR /root/code diff --git a/credentials/.gitignore b/maven-credentials/.gitignore similarity index 100% rename from credentials/.gitignore rename to maven-credentials/.gitignore From 622ed8633d4b53b098bbc3c6e0e34d847b6df3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn?= Date: Fri, 14 Feb 2025 17:21:47 +0000 Subject: [PATCH 13/13] update compose file to have version number read from VERSION on CI action --- docker-compose.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bc1db1d..7490d1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,10 @@ -version: "3.8" - -# Services services: - # FeatureInfoAgent feature-info-agent: - image: ghcr.io/cambridge-cares/feature-info-agent:latest + image: ghcr.io/cambridge-cares/feature-info-agent:4.0.0 + container_name: feature-info-agent + restart: on-failure:3 build: . + labels: + authors: "support@cmcl.io" + description: "TWA Feature Info Agent image."