|
| 1 | +name: "Build" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + tags: |
| 8 | + description: "Extra Tags: comma,separated" |
| 9 | + dev: |
| 10 | + description: "Development Build" |
| 11 | + type: boolean |
| 12 | + default: true |
| 13 | + #release: |
| 14 | + # types: [published] |
| 15 | + |
| 16 | +env: |
| 17 | + dev: ${{ (inputs.dev || github.event.release.prerelease) && 'dev' || '' }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: "Build" |
| 22 | + runs-on: ubuntu-latest |
| 23 | + timeout-minutes: 15 |
| 24 | + |
| 25 | + permissions: |
| 26 | + contents: write |
| 27 | + packages: write |
| 28 | + |
| 29 | + environment: |
| 30 | + name: ghcr |
| 31 | + url: https://github.com/cssnr/chat-server/pkgs/container/chat-server |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: "Debug CTX github" |
| 35 | + if: ${{ !github.event.act }} |
| 36 | + continue-on-error: true |
| 37 | + env: |
| 38 | + GITHUB_CTX: ${{ toJSON(github) }} |
| 39 | + run: echo "$GITHUB_CTX" |
| 40 | + |
| 41 | + - name: "Debug" |
| 42 | + continue-on-error: true |
| 43 | + run: | |
| 44 | + echo "github.ref_name: ${{ github.ref_name }}" |
| 45 | + echo "inputs.tags: ${{ inputs.tags }}" |
| 46 | + echo "inputs.dev: ${{ inputs.dev }}" |
| 47 | + echo "env.dev: ${{ env.dev }}" |
| 48 | +
|
| 49 | + - name: "Checkout" |
| 50 | + uses: actions/checkout@v6 |
| 51 | + |
| 52 | + - name: "Docker Login" |
| 53 | + uses: docker/login-action@v4 |
| 54 | + with: |
| 55 | + registry: ghcr.io |
| 56 | + username: ${{ vars.GHCR_USER }} |
| 57 | + password: ${{ secrets.GHCR_PASS }} |
| 58 | + |
| 59 | + - name: "Setup QEMU" |
| 60 | + uses: docker/setup-qemu-action@v4 |
| 61 | + |
| 62 | + - name: "Setup Buildx" |
| 63 | + uses: docker/setup-buildx-action@v4 |
| 64 | + with: |
| 65 | + platforms: linux/amd64,linux/arm64 |
| 66 | + |
| 67 | + - name: "Update Version Tags" |
| 68 | + id: version |
| 69 | + uses: cssnr/update-version-tags-action@v2 |
| 70 | + with: |
| 71 | + prefix: "" |
| 72 | + dry_run: true |
| 73 | + tags: | |
| 74 | + ${{ inputs.tags }} |
| 75 | +
|
| 76 | + - name: "Debug Version Tags" |
| 77 | + continue-on-error: true |
| 78 | + run: | |
| 79 | + echo "github.ref_name: ${{ github.ref_name }}" |
| 80 | + echo "tags1: ${{ env.dev }}" |
| 81 | + echo "tags2: ${{ steps.version.outputs.tags }}" |
| 82 | + echo "tags3: ${{ inputs.tags }}" |
| 83 | +
|
| 84 | + - name: "Generate Docker Tags" |
| 85 | + id: tags |
| 86 | + uses: cssnr/docker-tags-action@v2 |
| 87 | + with: |
| 88 | + images: "ghcr.io/${{ github.repository }}" |
| 89 | + tags: | |
| 90 | + ${{ env.dev }} |
| 91 | + ${{ steps.version.outputs.tags }} |
| 92 | + ${{ inputs.tags }} |
| 93 | +
|
| 94 | + - name: "Debug Docker Tags" |
| 95 | + continue-on-error: true |
| 96 | + run: | |
| 97 | + echo "github.ref_name: ${{ github.ref_name }}" |
| 98 | + echo "tags: ${{ steps.tags.outputs.tags }}" |
| 99 | + echo "labels: ${{ steps.tags.outputs.labels }}" |
| 100 | + echo "annotations: ${{ steps.tags.outputs.annotations }}" |
| 101 | +
|
| 102 | + - name: "Build and Push" |
| 103 | + uses: docker/build-push-action@v7 |
| 104 | + with: |
| 105 | + context: . |
| 106 | + push: true |
| 107 | + platforms: linux/amd64,linux/arm64 |
| 108 | + tags: ${{ steps.tags.outputs.tags }} |
| 109 | + labels: ${{ steps.tags.outputs.labels }} |
| 110 | + annotations: ${{ steps.tags.outputs.annotations }} |
| 111 | + cache-from: type=gha |
| 112 | + cache-to: type=gha,mode=max |
| 113 | + build-args: | |
| 114 | + VERSION=${{ github.ref_name }} |
| 115 | +
|
| 116 | + - name: "Send Failure Notification" |
| 117 | + if: ${{ failure() }} |
| 118 | + uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0 |
| 119 | + with: |
| 120 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 121 | + description: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
0 commit comments