Skip to content

Commit 2ea7ec5

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 2ea7ec5

File tree

1 file changed

+106
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)