|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +permissions: |
| 6 | + contents: write |
| 7 | + packages: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + backend: |
| 11 | + name: Backend |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + - name: Setup Java |
| 16 | + uses: actions/setup-java@v4 |
| 17 | + with: |
| 18 | + distribution: 'temurin' |
| 19 | + java-version: 21 |
| 20 | + - name: Setup Gradle |
| 21 | + uses: gradle/actions/setup-gradle@v3 |
| 22 | + - name: Artifact |
| 23 | + uses: actions/upload-artifact@v3 |
| 24 | + with: |
| 25 | + name: rm-monitor |
| 26 | + path: ./build/libs |
| 27 | + |
| 28 | + release: |
| 29 | + name: Release |
| 30 | + runs-on: ubuntu-latest |
| 31 | + if: github.event_name == 'push' |
| 32 | + needs: [ backend ] |
| 33 | + outputs: |
| 34 | + new_version: ${{ steps.should_push.outputs.new_version }} |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Set up Node.js |
| 42 | + uses: actions/setup-node@v4 |
| 43 | + with: |
| 44 | + node-version: '20' |
| 45 | + |
| 46 | + - name: Fetch Previous version |
| 47 | + id: get-previous-tag |
| 48 | + uses: actions-ecosystem/[email protected] |
| 49 | + |
| 50 | + - name: mkdir |
| 51 | + run: | |
| 52 | + mkdir dist |
| 53 | +
|
| 54 | + - name: Download Artifact |
| 55 | + uses: actions/download-artifact@v3 |
| 56 | + with: |
| 57 | + name: rm-monitor |
| 58 | + path: ./dist |
| 59 | + |
| 60 | + - name: Release |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + run: yarn global add semantic-release @semantic-release/changelog && semantic-release |
| 64 | + |
| 65 | + - name: Fetch Current version |
| 66 | + id: get-current-tag |
| 67 | + uses: actions-ecosystem/[email protected] |
| 68 | + |
| 69 | + - name: Output New Version |
| 70 | + id: should_push |
| 71 | + run: | |
| 72 | + old_version=${{steps.get-previous-tag.outputs.tag}} |
| 73 | + new_version=${{steps.get-current-tag.outputs.tag }} |
| 74 | +
|
| 75 | + if [ "$old_version" != "$new_version" ]; then |
| 76 | + echo "new_version=$new_version" >> $GITHUB_OUTPUT |
| 77 | + else |
| 78 | + echo "new_version=" >> $GITHUB_OUTPUT |
| 79 | + fi |
| 80 | +
|
| 81 | + docker: |
| 82 | + runs-on: ubuntu-latest |
| 83 | + needs: [ release ] |
| 84 | + if: github.event_name == 'push' && needs.release.outputs.new_version != '' |
| 85 | + steps: |
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Set up Docker Buildx |
| 90 | + uses: docker/setup-buildx-action@v3 |
| 91 | + |
| 92 | + - name: Buildx Cache |
| 93 | + id: buildx-cache |
| 94 | + uses: docker/setup-buildx-action@v3 |
| 95 | + with: |
| 96 | + driver-opts: name=gha |
| 97 | + |
| 98 | + - name: Buildx Cache Load |
| 99 | + id: buildx-cache-load |
| 100 | + uses: docker/setup-buildx-action@v3 |
| 101 | + with: |
| 102 | + driver-opts: name=gha |
| 103 | + action: load |
| 104 | + |
| 105 | + - name: Login to Docker Hub |
| 106 | + if: github.event_name != 'pull_request' |
| 107 | + uses: docker/login-action@v3 |
| 108 | + with: |
| 109 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 110 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 111 | + |
| 112 | + - name: Login to GHCR |
| 113 | + if: github.event_name != 'pull_request' |
| 114 | + uses: docker/login-action@v3 |
| 115 | + with: |
| 116 | + registry: ghcr.io |
| 117 | + username: ${{ github.repository_owner }} |
| 118 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Docker Push |
| 121 | + uses: docker/build-push-action@v5 |
| 122 | + if: github.event_name == 'push' |
| 123 | + with: |
| 124 | + context: . |
| 125 | + push: true |
| 126 | + platforms: linux/amd64 |
| 127 | + tags: | |
| 128 | + scutrobot/rm-monitor:latest |
| 129 | + scutrobot/rm-monitor:${{ needs.release.outputs.new_version }} |
| 130 | + ghcr.io/scutrobot/rm-monitor:latest |
| 131 | + ghcr.io/scutrobot/rm-monitor:${{ needs.release.outputs.new_version }} |
| 132 | + build-args: | |
| 133 | + VERSION=${{ needs.release.outputs.new_version }} |
| 134 | + labels: | |
| 135 | + org.opencontainers.image.source=https://github.com/scutrobot/rm-monitor |
| 136 | + org.opencontainers.image.revision=${{ github.sha }} |
| 137 | + org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} |
| 138 | + org.opencontainers.image.version=${{ needs.release.outputs.new_version }} |
| 139 | + org.opencontainers.image.title=rm-monitor ${{ needs.release.outputs.new_version }} |
| 140 | + org.opencontainers.image.description="robomaster monitor" |
| 141 | + org.opencontainers.image.licenses=AGPL-3.0 |
| 142 | + cache-from: type=gha |
| 143 | + cache-to: type=gha,mode=max |
0 commit comments