1+ name : Build and Release
2+
3+ on :
4+ push :
5+ branches :
6+ - develop
7+ - main
8+ pull_request :
9+ branches :
10+ - main
11+
12+ permissions :
13+ contents : write
14+ issues : write
15+ pull-requests : write
16+
17+ concurrency :
18+ group : ${{ github.workflow }}-${{ github.ref }}
19+ cancel-in-progress : true
20+
21+ jobs :
22+ build-base :
23+ runs-on : ubuntu-latest
24+ steps :
25+ - uses : actions/checkout@v3
26+ - name : Set up Docker Buildx
27+ uses : docker/setup-buildx-action@v3
28+ - name : Login to GitHub Container Registry
29+ uses : docker/login-action@v3
30+ with :
31+ registry : ghcr.io
32+ username : ${{ github.actor }}
33+ password : ${{ secrets.GHCR_PAT }}
34+ - name : Build and push base
35+ run : |
36+ echo "${{ secrets.GHCR_PAT }}" > github_token
37+ docker buildx build \
38+ --platform linux/arm64 \
39+ --provenance=false \
40+ --secret id=github_token,src=github_token \
41+ --target base \
42+ --tag ghcr.io/${{ github.repository_owner }}/lambda-shell-runtime:base \
43+ --push \
44+ .
45+ env :
46+ GITHUB_TOKEN : ${{ secrets.GHCR_PAT }}
47+
48+ build :
49+ needs : build-base
50+ runs-on : ubuntu-latest
51+ env :
52+ HTTP_CLI_VERSION : v1.0.1
53+ steps :
54+ - uses : actions/checkout@v3
55+ - uses : actions/setup-node@v3
56+ with :
57+ node-version : 20
58+ - uses : actions/cache@v3
59+ with :
60+ path : ~/.npm
61+ key : ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
62+ restore-keys : |
63+ ${{ runner.os }}-node-
64+ - run : npm ci
65+ - name : Set up QEMU
66+ uses : docker/setup-qemu-action@v3
67+ - name : Set up Docker Buildx
68+ uses : docker/setup-buildx-action@v3
69+ - name : Create and use buildx builder
70+ run : |
71+ docker buildx create --name shell-runtime-builder --driver docker-container --use
72+ docker buildx inspect shell-runtime-builder --bootstrap
73+ - name : Cache Docker layers
74+ uses : actions/cache@v3
75+ with :
76+ path : /tmp/.buildx-cache
77+ key : ${{ runner.os }}-buildx-${{ github.sha }}
78+ restore-keys : |
79+ ${{ runner.os }}-buildx-
80+ - name : Set version
81+ id : version
82+ env :
83+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
84+ run : |
85+ if [ "${{ github.ref_name }}" = "main" ]; then
86+ # Get semantic version for main branch
87+ VERSION=$(npx semantic-release --no-ci --dry-run --branch main 2>&1 | grep -oP 'The next release version is \K[0-9]+\.[0-9]+\.[0-9]+' || echo "")
88+ if [ -z "$VERSION" ]; then
89+ echo "No release needed"
90+ echo "VERSION=develop" >> $GITHUB_ENV
91+ echo "SHOULD_RELEASE=false" >> $GITHUB_ENV
92+ else
93+ echo "VERSION=$VERSION" >> $GITHUB_ENV
94+ echo "SHOULD_RELEASE=true" >> $GITHUB_ENV
95+ fi
96+ else
97+ # Use branch name for develop
98+ echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
99+ echo "SHOULD_RELEASE=false" >> $GITHUB_ENV
100+ fi
101+ echo "Detected VERSION: $VERSION"
102+ - name : Log in to GHCR
103+ run : echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u skunxicat --password-stdin
104+ - name : Build and push images
105+ run : |
106+ echo "${{ secrets.GHCR_PAT }}" > github_token
107+ export GITHUB_TOKEN="${{ secrets.GHCR_PAT }}"
108+
109+ # Build and push all variants
110+ make push VERSION="$VERSION" REGISTRY="ghcr.io/${{ github.repository_owner }}"
111+ shell : bash
112+ - name : Create release
113+ if : env.SHOULD_RELEASE == 'true'
114+ run : npx semantic-release
115+ env :
116+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117+ GHCR_PAT : ${{ secrets.GHCR_PAT }}
0 commit comments