Revert "Potential fix for code scanning alert no. 22: Workflow does n… #17
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
| name: Deploy | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - hotfix | |
| - develop | |
| - early-access | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| uses: ./.github/workflows/test.yml | |
| docker: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - linux/amd64 | |
| - linux/arm64 | |
| outputs: | |
| version: ${{ steps.package-version.outputs.current-version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: "${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' && 0 || 1 }}" | |
| - name: Fetch Current Package Version | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' || github.ref == 'refs/heads/develop' | |
| id: package-version | |
| uses: martinbeentjes/npm-get-version-action@v1.3.1 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: phalcode | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: phalcode | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: ${{ matrix.platform }} | |
| tags: | | |
| phalcode/gamevault-backend | |
| ghcr.io/phalcode/gamevault-backend | |
| outputs: type=image,push-by-digest=true,name-canonical=true,push=true | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ strategy.job-index }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| manifest: | |
| needs: docker | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: /tmp/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: phalcode | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: phalcode | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create manifest list and push | |
| run: | | |
| BRANCH="${GITHUB_REF#refs/heads/}" | |
| VERSION="${{ needs.docker.outputs.version }}" | |
| push_manifest() { | |
| local REPO=$1 | |
| local TAGS=$2 | |
| local ARGS="" | |
| for tag in $TAGS; do | |
| ARGS="$ARGS -t $REPO:$tag" | |
| done | |
| docker buildx imagetools create $ARGS \ | |
| $(printf "$REPO@sha256:%s " $(ls /tmp/digests)) | |
| } | |
| case "$BRANCH" in | |
| master|hotfix) | |
| push_manifest "phalcode/gamevault-backend" "latest $VERSION" | |
| push_manifest "ghcr.io/phalcode/gamevault-backend" "latest $VERSION" | |
| ;; | |
| develop) | |
| push_manifest "phalcode/gamevault-backend" "unstable" | |
| push_manifest "ghcr.io/phalcode/gamevault-backend" "unstable" | |
| ;; | |
| early-access) | |
| push_manifest "phalcode/gamevault-backend" "early-access" | |
| push_manifest "ghcr.io/phalcode/gamevault-backend" "early-access" | |
| ;; | |
| esac | |
| - name: Create Github Tag & Release | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' | |
| id: release | |
| uses: CupOfTea696/gh-action-auto-release@v1.0.2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Discord notification | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' | |
| uses: Ilshidur/action-discord@master | |
| env: | |
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_BOT_WEBHOOK }} | |
| with: | |
| 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" | |
| sonarcloud: | |
| needs: test | |
| if: github.ref == 'refs/heads/develop' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: SonarCloud Scan | |
| uses: SonarSource/sonarcloud-github-action@master | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |