fork/chhoto-url

git clone https://git.julia.blue/fork/chhoto-url

Sayantan Santranew: Added support for custom site title (#136)933042e

unicode
9.0 KiB275 linesraw
1# SPDX-FileCopyrightText: 2023-2026 Sayantan Santra <sayantan.santra689@gmail.com>
2# SPDX-License-Identifier: MIT
3
4name: Test and Release
5on:
6  push:
7    tags:
8      - "*"
9    branches: ["dev"]
10    paths: ["backend/**", "frontend/**"]
11  workflow_dispatch:
12env:
13  CARGO_TERM_COLOR: always
14  IMAGE_NAME: chhoto-url
15
16jobs:
17  # Build artifacts
18  build:
19    name: Build and Test - ${{ matrix.platform.os-name }}
20    if: |
21      github.ref_type == 'tag' ||
22      !startsWith(github.event.head_commit.message, 'build: Bumped version to')
23    strategy:
24      matrix:
25        platform:
26          - os-name: Linux-x86_64
27            target: x86_64-unknown-linux-musl
28
29          - os-name: Linux-arm64
30            target: aarch64-unknown-linux-musl
31
32          - os-name: Linux-armv7
33            target: armv7-unknown-linux-musleabihf
34
35          - os-name: Linux-riscv64
36            target: riscv64gc-unknown-linux-musl
37            # Need to use an unreleased version for now
38            cross-version: a5c1c64f0810eb90c790e94b7904b27dccc02287
39
40    runs-on: ubuntu-latest
41    steps:
42      - name: Checkout
43        uses: actions/checkout@v6
44      - name: Compute short SHA
45        id: vars
46        shell: bash
47        run: echo "short_sha=$(echo ${{ github.sha }} | cut -c1-7)" >> "$GITHUB_OUTPUT"
48        # Build the binaries and upload
49      - name: Build binary and test
50        uses: houseabsolute/actions-rust-cross@v1
51        env:
52          CARGO_GIT_COMMIT: ${{ github.ref_type != 'tag' && steps.vars.outputs.short_sha || '' }}
53        with:
54          command: both
55          target: ${{ matrix.platform.target }}
56          args: "--locked --release --manifest-path=backend/Cargo.toml"
57          cross-version: ${{ matrix.platform.cross-version }}
58          rust-cache-parameters: '{"workspaces":"backend -> target"}'
59      - name: Upload artifacts
60        uses: actions/upload-artifact@v7
61        with:
62          name: ${{ matrix.platform.target }}
63          path: ./backend/target/${{ matrix.platform.target }}/release/${{ env.IMAGE_NAME }}
64          retention-days: 1
65          if-no-files-found: error
66
67  # Push dev image
68  dev:
69    name: Push dev image
70    if: github.ref_type != 'tag'
71    runs-on: ubuntu-latest
72    permissions:
73      id-token: write
74      contents: write
75      packages: write
76      attestations: write
77    needs: build
78    steps:
79      # Prep the files
80      - name: Checkout repository
81        uses: actions/checkout@v6
82        with:
83          lfs: true
84          fetch-depth: 0
85      - name: Download artifacts
86        uses: actions/download-artifact@v8
87      - name: Move stuff around and fix permissions
88        run: |
89          for f in *-unknown-linux-musl*
90          do
91            mkdir -p backend/target/$f/release
92            mv $f/chhoto-url backend/target/$f/release/
93            chmod +x backend/target/$f/release/chhoto-url
94          done
95      - name: Display current directory structure
96        run: ls -R
97      - name: Log in to the Container registry
98        uses: docker/login-action@v4
99        with:
100          registry: ghcr.io
101          username: ${{ github.actor }}
102          password: ${{ secrets.GITHUB_TOKEN }}
103
104      # Extract metadata
105      - name: Extract metadata (tags, labels) for Docker - dev
106        id: meta-dev
107        uses: docker/metadata-action@v6
108        env:
109          DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
110        with:
111          images: |
112            ghcr.io/sintan1729/${{ env.IMAGE_NAME }}
113          tags: |
114            type=raw,value=dev
115
116      # Build and push docker images
117      - name: Set up Docker Buildx
118        uses: docker/setup-buildx-action@v4
119      - name: Build and push Docker image - dev
120        id: push-dev
121        uses: docker/build-push-action@v7
122        with:
123          context: .
124          push: true
125          file: deploy/Containerfile.alpine
126          tags: ${{ steps.meta-dev.outputs.tags }}
127          labels: ${{ steps.meta-dev.outputs.labels }}
128          platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64
129          annotations: ${{ steps.meta-dev.outputs.annotations }}
130
131      # Attestation
132      - name: Generate artifact attestation - dev
133        uses: actions/attest@v4
134        with:
135          subject-name: sintan1729/${{ env.IMAGE_NAME }}
136          subject-digest: ${{ steps.push-dev.outputs.digest }}
137
138  # Push release images
139  release:
140    name: Push release images
141    if: github.ref_type == 'tag'
142    runs-on: ubuntu-latest
143    permissions:
144      id-token: write
145      contents: write
146      packages: write
147      attestations: write
148    needs: build
149    steps:
150      # Prep the files
151      - name: Checkout repository
152        uses: actions/checkout@v6
153        with:
154          lfs: true
155          fetch-depth: 0
156      - name: Download artifacts
157        uses: actions/download-artifact@v8
158      - name: Move stuff around and fix permissions
159        run: |
160          for f in *-unknown-linux-musl*
161          do
162            mkdir -p backend/target/$f/release
163            mv $f/chhoto-url backend/target/$f/release/
164            chmod +x backend/target/$f/release/chhoto-url
165          done
166      - name: Minify frontend for release
167        run: |
168          mv frontend/ frontend-original/
169          sudo apt update
170          sudo apt install minify
171          minify -rs frontend-original/ -o frontend/
172          mkdir -p empty-dir # Needed for scratch
173      - name: Display current directory structure
174        run: ls -R
175      - name: Log in to the Docker Hub
176        uses: docker/login-action@v4
177        with:
178          username: ${{ secrets.DOCKER_USERNAME }}
179          password: ${{ secrets.DOCKER_PASSWORD }}
180      - name: Log in to the Container registry
181        uses: docker/login-action@v4
182        with:
183          registry: ghcr.io
184          username: ${{ github.actor }}
185          password: ${{ secrets.GITHUB_TOKEN }}
186
187      # Extract metadata
188      - name: Extract metadata (tags, labels) for Docker - alpine
189        id: meta-alpine
190        uses: docker/metadata-action@v6
191        env:
192          DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
193        with:
194          images: |
195            sintan1729/${{ env.IMAGE_NAME }}
196            ghcr.io/sintan1729/${{ env.IMAGE_NAME }}
197          tags: |
198            type=semver,pattern={{major}}-alpine
199            type=semver,pattern={{major}}.{{minor}}-alpine
200            type=semver,pattern={{version}}-alpine
201            type=raw,value=latest-alpine
202            type=raw,value=alpine
203      - name: Extract metadata (tags, labels) for Docker - scratch
204        id: meta-scratch
205        uses: docker/metadata-action@v6
206        env:
207          DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
208        with:
209          images: |
210            sintan1729/${{ env.IMAGE_NAME }}
211            ghcr.io/sintan1729/${{ env.IMAGE_NAME }}
212          tags: |
213            type=semver,pattern={{major}}
214            type=semver,pattern={{major}}.{{minor}}
215            type=semver,pattern={{version}}
216            type=raw,value=latest
217            type=raw,value=scratch
218
219      # Build and push docker images
220      - name: Set up Docker Buildx
221        uses: docker/setup-buildx-action@v4
222      - name: Build and push Docker image - alpine
223        id: push-alpine
224        uses: docker/build-push-action@v7
225        with:
226          context: .
227          push: true
228          file: deploy/Containerfile.alpine
229          tags: |
230            ${{ steps.meta-alpine.outputs.tags }}
231            ghcr.io/sintan1729/${{ env.IMAGE_NAME }}:dev
232          labels: ${{ steps.meta-alpine.outputs.labels }}
233          platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64
234          annotations: ${{ steps.meta-alpine.outputs.annotations }}
235      - name: Build and push Docker image - scratch
236        id: push-scratch
237        uses: docker/build-push-action@v7
238        with:
239          context: .
240          push: true
241          file: deploy/Containerfile.scratch
242          tags: ${{ steps.meta-scratch.outputs.tags }}
243          labels: ${{ steps.meta-scratch.outputs.labels }}
244          platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64
245          annotations: ${{ steps.meta-scratch.outputs.annotations }}
246
247      # Attestation
248      - name: Generate artifact attestation - alpine
249        uses: actions/attest@v4
250        with:
251          subject-name: sintan1729/${{ env.IMAGE_NAME }}
252          subject-digest: ${{ steps.push-alpine.outputs.digest }}
253      - name: Generate artifact attestation - scratch
254        uses: actions/attest@v4
255        with:
256          subject-name: sintan1729/${{ env.IMAGE_NAME }}
257          subject-digest: ${{ steps.push-scratch.outputs.digest }}
258
259      # Create a release with changelog
260      - name: Generate a changelog
261        uses: orhun/git-cliff-action@v4
262        id: git-cliff
263        with:
264          config: .github/cliff.toml
265          args: --latest --strip header
266        env:
267          GITHUB_REPO: ${{ github.repository }}
268          OUTPUT: CHANGELOG.md
269      - name: Show the changelog
270        run: cat CHANGELOG.md
271      - name: Release
272        uses: softprops/action-gh-release@v3
273        with:
274          body_path: ${{ steps.git-cliff.outputs.changelog }}
275          make_latest: true