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