Fix FIRE-DN9 #43
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: Build and Deploy | |
| on: | |
| push: | |
| branches: ["master", "deploy"] | |
| paths-ignore: | |
| - '.github/**' | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Lowercase Repo Name | |
| id: repo_lc | |
| run: echo "repo=${GITHUB_REPOSITORY,,}" >> ${GITHUB_OUTPUT} | |
| - name: Check Image Build Needed | |
| id: check-image | |
| run: | | |
| if docker manifest inspect ghcr.io/${{ steps.repo_lc.outputs.repo }}:${{ github.sha }} > /dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and Push Image | |
| if: steps.check-image.outputs.exists != 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/${{ steps.repo_lc.outputs.repo }}:latest | |
| ghcr.io/${{ steps.repo_lc.outputs.repo }}:${{ github.sha }} | |
| deploy-sync: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Determine Target Environment | |
| id: env-check | |
| run: | | |
| if [[ "${{ github.ref_name }}" == "deploy" ]]; then | |
| echo "target=production" >> $GITHUB_OUTPUT | |
| else | |
| echo "target=staging" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update Manifest in Infra Repo | |
| run: | | |
| git clone https://x-access-token:${{ secrets.INFRA_REPO_TOKEN }}@github.com/FireDiscordBot/k3s-infra.git | |
| cd k3s-infra | |
| TARGET_ENV=${{ steps.env-check.outputs.target }} | |
| sed -i "s|image: ghcr.io/firediscordbot/bot:.*|image: ghcr.io/firediscordbot/bot:${{ github.sha }}|g" clusters/$TARGET_ENV/fire/fire.yaml | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add . | |
| git commit -m "deploy($TARGET_ENV): update bot to ${{ github.sha }}" | |
| git push |