Sort out the silly syntax to get a silly one line from a message. Her… #23
This file contains hidden or 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
| # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
| name: Build and Publish Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - tomcat-10 | |
| paths-ignore: | |
| - "*.md" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| version: | |
| - 9-jdk8 | |
| - 9-jdk8-oracle | |
| - 9-jdk17 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Select logging library | |
| run: | | |
| # if matrix version is jdk8, set variable to warwick-logging-1.1-all.jar | |
| # else use warwick-logging-1.4.jar | |
| if [ "${{ matrix.version }}" = "9-jdk8" ]; then | |
| echo "Using old logging library for Tomcat 9 with JDK 8" >> $GITHUB_STEP_SUMMARY | |
| echo "LOGGING_LIB=warwick-logging-1.1-all.jar" >> $GITHUB_ENV | |
| else | |
| echo "Using newer logging library" >> $GITHUB_STEP_SUMMARY | |
| echo "LOGGING_LIB=warwick-logging-1.4-all.jar" >> $GITHUB_ENV | |
| fi | |
| - name: Calculate source image tag | |
| run: | | |
| # Remove -oracle from matrix version if it exists and put in env var | |
| SOURCE_IMAGE_TAG=$(echo "${{ matrix.version }}" | sed 's/-oracle//') | |
| echo "SOURCE_IMAGE_TAG=${SOURCE_IMAGE_TAG}" >> $GITHUB_ENV | |
| - name: Prune Oracle library | |
| run: | | |
| # if matrix version doesn't contain oracle, delete tomcat/lib/ojdbc*.jar | |
| if [[ "${{ matrix.version }}" != *"oracle"* ]]; then | |
| echo "Removing Oracle library" >> $GITHUB_STEP_SUMMARY | |
| rm -f tomcat/lib/ojdbc*.jar | |
| fi | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| build-args: | | |
| TOMCAT_VERSION=${{ env.SOURCE_IMAGE_TAG }} | |
| LOGGING_LIB=${{ env.LOGGING_LIB }} | |
| tags: universityofwarwick/dev-tomcat:${{ matrix.version }} | |
| - name: Get first line of commit message | |
| id: commitmsg | |
| run: | | |
| FIRST_LINE="$(echo "$COMMIT_MESSAGE" | head -n 1)" | |
| echo "message=$FIRST_LINE" >> "$GITHUB_OUTPUT" | |
| env: | |
| COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | |
| - name: Notify Slack | |
| uses: slackapi/slack-github-action@v2.1.1 | |
| with: | |
| method: chat.postMessage | |
| token: ${{ secrets.SLACK_BOT_TOKEN }} | |
| payload: | | |
| "channel": "#utility-libraries", | |
| "text": "A new version of *universityofwarwick/dev-tomcat:${{ env.SOURCE_IMAGE_TAG }}* was pushed to Docker Hub!", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "A new version of *universityofwarwick/dev-tomcat:${{ env.SOURCE_IMAGE_TAG }}* was pushed to Docker Hub!" | |
| } | |
| }, | |
| { | |
| "type": "context", | |
| "elements": [ | |
| { | |
| "type": "mrkdwn", | |
| "text": "`${{ github.sha }}`" | |
| }, | |
| { | |
| "type": "plain_text", | |
| "text": "${{ steps.commitmsg.outputs.message }}" | |
| } | |
| ] | |
| } | |
| ] | |