|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - hotfix |
| 8 | + - develop |
| 9 | + - early-access |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: deploy-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + uses: ./.github/workflows/test.yml |
| 18 | + |
| 19 | + docker: |
| 20 | + needs: test |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + platform: |
| 26 | + - linux/amd64 |
| 27 | + - linux/arm64 |
| 28 | + outputs: |
| 29 | + version: ${{ steps.package-version.outputs.current-version }} |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: "${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' && 0 || 1 }}" |
| 35 | + |
| 36 | + - name: Fetch Current Package Version |
| 37 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' || github.ref == 'refs/heads/develop' |
| 38 | + id: package-version |
| 39 | + uses: martinbeentjes/npm-get-version-action@v1.3.1 |
| 40 | + |
| 41 | + - name: Set up QEMU |
| 42 | + uses: docker/setup-qemu-action@v3 |
| 43 | + |
| 44 | + - name: Set up Docker Buildx |
| 45 | + uses: docker/setup-buildx-action@v3 |
| 46 | + |
| 47 | + - name: Login to Docker Hub |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + username: phalcode |
| 51 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Login to GitHub Container Registry |
| 54 | + uses: docker/login-action@v3 |
| 55 | + with: |
| 56 | + registry: ghcr.io |
| 57 | + username: phalcode |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + - name: Build and Push by digest |
| 61 | + id: build |
| 62 | + uses: docker/build-push-action@v6 |
| 63 | + with: |
| 64 | + platforms: ${{ matrix.platform }} |
| 65 | + tags: | |
| 66 | + phalcode/gamevault-backend |
| 67 | + ghcr.io/phalcode/gamevault-backend |
| 68 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 69 | + cache-from: type=gha |
| 70 | + cache-to: type=gha,mode=max |
| 71 | + |
| 72 | + - name: Export digest |
| 73 | + run: | |
| 74 | + mkdir -p /tmp/digests |
| 75 | + digest="${{ steps.build.outputs.digest }}" |
| 76 | + touch "/tmp/digests/${digest#sha256:}" |
| 77 | +
|
| 78 | + - name: Upload digest |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: digests-${{ strategy.job-index }} |
| 82 | + path: /tmp/digests/* |
| 83 | + if-no-files-found: error |
| 84 | + retention-days: 1 |
| 85 | + |
| 86 | + manifest: |
| 87 | + needs: docker |
| 88 | + runs-on: ubuntu-latest |
| 89 | + steps: |
| 90 | + - name: Download digests |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + path: /tmp/digests |
| 94 | + pattern: digests-* |
| 95 | + merge-multiple: true |
| 96 | + |
| 97 | + - name: Set up Docker Buildx |
| 98 | + uses: docker/setup-buildx-action@v3 |
| 99 | + |
| 100 | + - name: Login to Docker Hub |
| 101 | + uses: docker/login-action@v3 |
| 102 | + with: |
| 103 | + username: phalcode |
| 104 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 105 | + |
| 106 | + - name: Login to GitHub Container Registry |
| 107 | + uses: docker/login-action@v3 |
| 108 | + with: |
| 109 | + registry: ghcr.io |
| 110 | + username: phalcode |
| 111 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + |
| 113 | + - name: Create manifest list and push |
| 114 | + run: | |
| 115 | + BRANCH="${GITHUB_REF#refs/heads/}" |
| 116 | + VERSION="${{ needs.docker.outputs.version }}" |
| 117 | +
|
| 118 | + push_manifest() { |
| 119 | + local REPO=$1 |
| 120 | + local TAGS=$2 |
| 121 | + local ARGS="" |
| 122 | + for tag in $TAGS; do |
| 123 | + ARGS="$ARGS -t $REPO:$tag" |
| 124 | + done |
| 125 | + |
| 126 | + docker buildx imagetools create $ARGS \ |
| 127 | + $(printf "$REPO@sha256:%s " $(ls /tmp/digests)) |
| 128 | + } |
| 129 | +
|
| 130 | + case "$BRANCH" in |
| 131 | + master|hotfix) |
| 132 | + push_manifest "phalcode/gamevault-backend" "latest $VERSION" |
| 133 | + push_manifest "ghcr.io/phalcode/gamevault-backend" "latest $VERSION" |
| 134 | + ;; |
| 135 | + develop) |
| 136 | + push_manifest "phalcode/gamevault-backend" "unstable" |
| 137 | + push_manifest "ghcr.io/phalcode/gamevault-backend" "unstable" |
| 138 | + ;; |
| 139 | + early-access) |
| 140 | + push_manifest "phalcode/gamevault-backend" "early-access" |
| 141 | + push_manifest "ghcr.io/phalcode/gamevault-backend" "early-access" |
| 142 | + ;; |
| 143 | + esac |
| 144 | +
|
| 145 | + - name: Create Github Tag & Release |
| 146 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' |
| 147 | + id: release |
| 148 | + uses: CupOfTea696/gh-action-auto-release@v1.0.2 |
| 149 | + env: |
| 150 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 151 | + |
| 152 | + - name: Discord notification |
| 153 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' |
| 154 | + uses: Ilshidur/action-discord@master |
| 155 | + env: |
| 156 | + DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_BOT_WEBHOOK }} |
| 157 | + with: |
| 158 | + args: "<@&1128857090090340382> New Release: {{ EVENT_PAYLOAD.repository.full_name }} v$VERSION has been deployed. Here are the changes: https://github.com/{{ EVENT_PAYLOAD.repository.full_name }}/releases/tag/$VERSION" |
| 159 | + |
| 160 | + sonarcloud: |
| 161 | + needs: test |
| 162 | + if: github.ref == 'refs/heads/develop' |
| 163 | + runs-on: ubuntu-latest |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + with: |
| 167 | + fetch-depth: 0 |
| 168 | + - name: SonarCloud Scan |
| 169 | + uses: SonarSource/sonarcloud-github-action@master |
| 170 | + env: |
| 171 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 172 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments