-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (87 loc) · 2.78 KB
/
nodejs.yml
File metadata and controls
105 lines (87 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Build Node.js
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
push:
branches:
- main
- develop
paths:
- 'nodejs/**'
- '.github/workflows/nodejs.yml'
release:
types: [published]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
jobs:
build:
name: "nodejs:${{ matrix.version }}"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
version:
- "20"
- "22"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set lowercase repository owner
id: owner
run: |
echo "value=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Check if Dockerfile exists
id: check
run: |
if [ -f "./nodejs/${{ matrix.version }}/Dockerfile" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
if: steps.check.outputs.exists == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: steps.check.outputs.exists == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
if: steps.check.outputs.exists == 'true'
id: tags
run: |
OWNER="${{ steps.owner.outputs.value }}"
VERSION="${{ matrix.version }}"
TAGS="${{ env.REGISTRY }}/$OWNER/nodejs:nodejs_$VERSION"
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/nodejs:latest"
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/nodejs:nodejs_$VERSION-dev"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
REL_TAG="${{ github.ref_name }}"
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/nodejs:nodejs_$VERSION-$REL_TAG"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push
if: steps.check.outputs.exists == 'true'
uses: docker/build-push-action@v6
with:
context: ./nodejs
file: ./nodejs/${{ matrix.version }}/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max