name: devops-01-maven on: push: branches: - main paths: - 'springboot-devops/devops-01-maven/**' - '.github/workflows/build-devops01-maven-project.yml' jobs: devops-01-maven: runs-on: ubuntu-latest steps: - name: checkout source code uses: actions/checkout@v3 with: fetch-depth: 1 - name: Setup jdk 17 uses: actions/setup-java@v3 with: distribution: temurin java-version: 17 - name: Setup Maven Action uses: s4u/setup-maven-action@v1.5.0 with: java-version: 17 maven-version: 3.8.6 - name: change github-action.sh Permission run: chmod +x ./springboot-devops/devops-01-maven/github-action.sh - name: run customize-action shell run: sh ./springboot-devops/devops-01-maven/github-action.sh ######################### ######################### ######################### - name: 創建一個 settings-xml 放在 maven 預設目錄 .m2/settings.xml uses: whelk-io/maven-settings-xml-action@v20 with: repositories: > [ { "id": "central", "url": "https://repo1.maven.org/maven2" }, { "id": "github", "url": "https://maven.pkg.github.com/yudady/spring-getting-started-guides", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } } ] servers: > [ { "id": "github", "username": "yudady", "password": "${{ secrets.GITHUB_TOKEN }}" } ] # output_file: .m2/settings.xml => Optional String path of to generate settings.xml. By default, ~/.m2/settings.xml is used. ####################################### ######### maven package ################ ####################################### - name: maven package run: mvn package working-directory: springboot-devops/devops-01-maven ###################################################################### ######### github packages 下載需要 authentication ... ############### ###################################################################### - name: Publish to GitHub Packages Apache Maven run: mvn deploy working-directory: springboot-devops/devops-01-maven env: USER_NAME: yudady GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ####################################### ######### docker start ################ ####################################### - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to Github Packages uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push uses: docker/build-push-action@v3 with: context: ./springboot-devops/devops-01-maven push: true tags: | yudady/devops-01-maven:latest ghcr.io/yudady/spring-getting-started-guides/devops-01-maven:latest build-args: JAR_FILE=./target/devops-01-maven-0.0.1-SNAPSHOT.jar ####################################### ######### slack start ################ ####################################### - name: slack report Status uses: ravsamhq/notify-slack-action@v2 if: always() with: status: ${{ job.status }} token: ${{ secrets.GITHUB_TOKEN }} notification_title: "{workflow} has {status_message}" message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>" footer: "Linked Repo <{repo_url}|{repo}> | <{workflow_url}|View Workflow>" notify_when: "success,failure,cancelled,warnings" env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}