Skip to content

Commit

Permalink
fix: docker build not showing version number (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Nov 21, 2024
1 parent fe3a5b3 commit fa6917e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ concurrency:
group: release

jobs:
build_docker:
uses: ./.github/workflows/docker.yml
with:
is_main_build: ${{ inputs.is_main_build }}
permissions:
contents: read
packages: write

build_web:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -223,7 +231,12 @@ jobs:
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}

create_release:
needs: [build_web, build_ios, build_android_play, build_android]
needs:
- build_web
- build_ios
- build_android_play
- build_android
- build_docker
if: inputs.is_main_build != true
runs-on: ubuntu-latest

Expand Down
33 changes: 26 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,61 @@
name: docker

on:
push:
branches:
- main
- release/*
tags:
- "*"
workflow_call:
inputs:
is_main_build:
type: boolean
required: true

pull_request:
branches:
- main
- release/*

jobs:
docker:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download bumped version artifacts
if: inputs.is_main_build
uses: actions/download-artifact@v4
with:
name: release-data

# If not main build, create .env file with APP_GIT_REF
- name: Create .env file
if: inputs.is_main_build != true
run: |
echo "APP_GIT_REF=${{ github.sha }}" >> .env
- name: Docker meta
id: metal
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v6
with:
Expand Down
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ FROM base AS builder
RUN apk add --no-cache git

# Prepare build deps
COPY package.json pnpm-lock.yaml .npmrc ./
# Copy .env conditionally https://stackoverflow.com/a/31532674/1319878
COPY package.json pnpm-lock.yaml .npmrc .en[v] ./
COPY patches ./patches

# Add APP_VERSION to .env if it doesn't already exist
RUN grep -q 'APP_VERSION=' .env || \
echo "APP_VERSION=`node -p \"require('./package.json').version\"`" >> .env

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

# Copy all source files
Expand Down
2 changes: 1 addition & 1 deletion src/routes/pages/settings/about/AppDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function AppDetails() {
<AppContainer>
<img src="/logo.png" alt="" />
<div>
Voyager <AppVersionInfo betaPrefix="Beta Track" betaAs="aside" />
Voyager <AppVersionInfo verbose betaAs="aside" />
<aside>by Alexander Harding</aside>
</div>
</AppContainer>
Expand Down
20 changes: 16 additions & 4 deletions src/routes/pages/settings/about/AppVersionInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";

interface AppVersionInfoProps {
betaAs?: React.ElementType;
betaPrefix?: string;
verbose?: boolean;
}

export default function AppVersionInfo({
Expand All @@ -20,14 +20,26 @@ export default function AppVersionInfo({
);
}

function BetaInfo({ betaPrefix }: AppVersionInfoProps) {
function BetaInfo({ verbose }: AppVersionInfoProps) {
if (import.meta.env.DEV) return <IonText color="danger">Development</IonText>;

// If the app version is different from the git ref (tag), it's a pre-release
if (!import.meta.env.APP_GIT_REF) return;

// e.g. pull request build
if (!import.meta.env.APP_BUILD) {
return (
<IonText color="danger">
{import.meta.env.APP_GIT_REF.slice(0, 7)}
</IonText>
);
}

// e.g. beta release
// if the app version is different from the git ref (tag)
if (import.meta.env.APP_GIT_REF !== import.meta.env.APP_VERSION)
return (
<IonText color="warning">
{betaPrefix && `${betaPrefix} – `}[{import.meta.env.APP_BUILD}]{" "}
{verbose && `Beta Track – `}[{import.meta.env.APP_BUILD}]{" "}
{import.meta.env.APP_GIT_REF.slice(0, 7)}
</IonText>
);
Expand Down

0 comments on commit fa6917e

Please sign in to comment.