|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + packages: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + runs-on: ubuntu-24.04-arm |
| 16 | + name: Test |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout Repository |
| 20 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 21 | + |
| 22 | + - name: Run Tests |
| 23 | + uses: ./.github/workflows/composite/test |
| 24 | + |
| 25 | + check-version: |
| 26 | + runs-on: ubuntu-24.04-arm |
| 27 | + name: Check Version |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout Repository |
| 31 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 32 | + |
| 33 | + - name: Check Greater Than latest |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: | |
| 37 | + latest_version=$(gh release view --json tagName -q .tagName || echo "0.0.0") |
| 38 | + newest_version=$(printf "%s\n%s" "$latest_version" "${{ github.ref_name }}" | sort -V | tail -n1) |
| 39 | +
|
| 40 | + if [[ "${{ github.ref_name }}" != "$newest_version" ]]; then |
| 41 | + echo "Tag is not newer than the latest release" >> /dev/stderr |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + |
| 45 | + - name: Check Web Package Version |
| 46 | + run: | |
| 47 | + web_version=$(cat web/package.json | jq -r ".version") |
| 48 | +
|
| 49 | + if [[ "${{ github.ref_name }}" != "$web_version" ]]; then |
| 50 | + echo "Web package version does not match tag" >> /dev/stderr |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + |
| 54 | + - name: Check Backend Package Version |
| 55 | + run: | |
| 56 | + backend_version=$(awk -F' *= *' ' |
| 57 | + $0 ~ /^\[package\]/ { in_package=1; next } |
| 58 | + in_package && $1 ~ /^version$/ { |
| 59 | + gsub(/["'\'']/, "", $2); print $2; exit |
| 60 | + } |
| 61 | + ' backend/Cargo.toml) |
| 62 | +
|
| 63 | + if [[ "${{ github.ref_name }}" != "$backend_version" ]]; then |
| 64 | + echo "Backend package version does not match tag" >> /dev/stderr |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + build-and-push-amd64: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + name: Build and Push for amd64 |
| 71 | + needs: |
| 72 | + - test |
| 73 | + - check-version |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Checkout Repository |
| 77 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 78 | + |
| 79 | + - name: Build and Push |
| 80 | + uses: ./.github/workflows/composite/build-and-push |
| 81 | + with: |
| 82 | + platform: amd64 |
| 83 | + |
| 84 | + build-and-push-arm64: |
| 85 | + runs-on: ubuntu-24.04-arm |
| 86 | + name: Build and Push for arm64 |
| 87 | + needs: |
| 88 | + - test |
| 89 | + - check-version |
| 90 | + |
| 91 | + steps: |
| 92 | + - name: Checkout Repository |
| 93 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 94 | + |
| 95 | + - name: Build and Push |
| 96 | + uses: ./.github/workflows/composite/build-and-push |
| 97 | + with: |
| 98 | + platform: arm64 |
| 99 | + |
| 100 | + publish: |
| 101 | + runs-on: ubuntu-24.04-arm |
| 102 | + name: Publish |
| 103 | + needs: |
| 104 | + - build-and-push-amd64 |
| 105 | + - build-and-push-arm64 |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout Repository |
| 109 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 110 | + with: |
| 111 | + fetch-depth: 0 |
| 112 | + |
| 113 | + - name: Generate Changelog |
| 114 | + env: |
| 115 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + run: | |
| 117 | + latest_version=$(gh release view --json tagName -q .tagName || echo "") |
| 118 | + if [[ "$latest_version" == "" ]]; then |
| 119 | + git log --pretty=format:"%s" > /tmp/changelog.txt |
| 120 | + else |
| 121 | + latest_version_commit=$(git rev-parse "$latest_version") |
| 122 | + git log $latest_version_commit..${{ github.sha }} --pretty=format:"%s" > /tmp/changelog.txt |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Publish |
| 126 | + uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836 # 2.3.3 |
| 127 | + with: |
| 128 | + body_path: /tmp/changelog.txt |
| 129 | + |
0 commit comments