Skip to content

Commit f3f30d4

Browse files
committed
ci(workflows): automatically generate Docker image on new app version release
Signed-off-by: Edward Ly <contact@edward.ly>
1 parent d9ea019 commit f3f30d4

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
4+
name: Publish CPU Image
5+
6+
on:
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
11+
permissions:
12+
packages: write
13+
contents: read
14+
15+
jobs:
16+
push_to_registry:
17+
name: Build image
18+
runs-on: ubuntu-22.04
19+
if: ${{ github.repository_owner == 'nextcloud' }}
20+
steps:
21+
- name: Set app env
22+
run: |
23+
# Split and keep last
24+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
25+
echo "APP_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
26+
27+
- name: Checkout
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
persist-credentials: false
31+
path: ${{ env.APP_NAME }}
32+
33+
- name: Read package.json node and npm engines version
34+
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
35+
id: versions
36+
# Continue if no package.json
37+
continue-on-error: true
38+
with:
39+
path: ${{ env.APP_NAME }}
40+
fallbackNode: '^20'
41+
fallbackNpm: '^10'
42+
43+
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
44+
# Skip if no package.json
45+
if: ${{ steps.versions.outputs.nodeVersion }}
46+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
47+
with:
48+
node-version: ${{ steps.versions.outputs.nodeVersion }}
49+
50+
- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
51+
# Skip if no package.json
52+
if: ${{ steps.versions.outputs.npmVersion }}
53+
run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'
54+
55+
- name: Build ${{ env.APP_NAME }}
56+
# Skip if no package.json
57+
if: ${{ steps.versions.outputs.nodeVersion }}
58+
env:
59+
CYPRESS_INSTALL_BINARY: 0
60+
run: |
61+
cd ${{ env.APP_NAME }}
62+
npm ci
63+
npm run build --if-present
64+
65+
- name: Set up QEMU
66+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
67+
68+
- name: Set up Docker Buildx
69+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
70+
71+
- name: Log in to GitHub Container Registry
72+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
73+
with:
74+
registry: ghcr.io
75+
username: ${{ github.actor }}
76+
password: ${{ secrets.GITHUB_TOKEN }}
77+
78+
- name: Available platforms
79+
run: echo ${{ steps.buildx.outputs.platforms }}
80+
81+
- name: Install xmlstarlet
82+
run: sudo apt-get update && sudo apt-get install -y xmlstarlet
83+
84+
- name: Extract version from XML
85+
id: extract_version
86+
run: |
87+
cd ${{ env.APP_NAME }}
88+
VERSION=$(xmlstarlet sel -t -v "//image-tag" appinfo/info.xml)
89+
echo "VERSION=$VERSION" >> $GITHUB_ENV
90+
91+
- name: Log version
92+
run: |
93+
echo "Extracted version: ${{ env.VERSION }}"
94+
95+
- name: Build container image
96+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
97+
with:
98+
push: true
99+
context: ./${{ env.APP_NAME }}
100+
platforms: linux/amd64
101+
tags:
102+
- ghcr.io/nextcloud/${{ env.APP_NAME }}:${{ env.VERSION }}
103+
- ghcr.io/nextcloud/${{ env.APP_NAME }}:latest
104+
build-args: |
105+
BUILD_TYPE=cpu

0 commit comments

Comments
 (0)