Build and Publish #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish | |
on: | |
schedule: | |
# At 04:00 on day-of-month 1. | |
- cron: "0 4 1 * *" | |
workflow_dispatch: | |
push: | |
branches: | |
- "main" | |
jobs: | |
prepare-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
latest: ${{ steps.latest-version.outputs.matrix }} | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@master | |
- name: Get Docker tags | |
id: get-tags | |
run: | | |
IMAGE_NAME="library/alpine" | |
curl -s "https://nodejs.org/download/release/index.json" > node_versions.json | |
- uses: cloudposse/github-action-jq@main | |
id: parse-tags | |
with: | |
compact: true | |
input: node_versions.json | |
#script: '[.[] | select(.version | test("v(1[8-9]|[2-9][0-9]).*"))] | map(.version) | .[0:200]' | |
script: '[.[] | select(.version | test("v(1[8-9]|[2-9][0-9]).*"))] | group_by(.version | match("v(\\d+).*").captures[0].string | tonumber) | map(max_by(.version | match("v(\\d+\\.\\d+).*").captures[0].string | split(".") as $parts | ($parts[0] | tonumber) * 1000 + ($parts[1] | tonumber))) | map({version: .version, major: (.version | match("v(\\d+).*").captures[0].string | tonumber)}) | .[0:200]' | |
- uses: cloudposse/github-action-jq@main | |
id: latest-version | |
with: | |
compact: true | |
input: node_versions.json | |
script: 'map(select(.version | startswith("v20"))) | max_by(.version) | .version' | |
- name: Set matrix for build | |
run: | | |
echo '{"tag": ${{ steps.parse-tags.outputs.output }}}' >> config.json | |
- uses: cloudposse/github-action-jq@main | |
id: reparse-tags | |
with: | |
compact: true | |
input: config.json | |
script: "." | |
- run: echo 'matrix=${{ steps.reparse-tags.outputs.output }}' >> $GITHUB_OUTPUT | |
id: set-matrix | |
build: | |
needs: prepare-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USER }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
logout: true | |
- name: Parse version | |
id: parse_version | |
run: | | |
VERSION=${{ matrix.tag.version }} | |
PARSED_VERSION=${VERSION#v} | |
echo "PARSED_VERSION=$PARSED_VERSION" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Build | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
ALPINE_VERSION=3.19 | |
NODE_MAJOR=${{ matrix.tag.major }} | |
NODE_VERSION=${{ steps.parse_version.outputs.PARSED_VERSION }} | |
context: . | |
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 | |
push: true | |
tags: | | |
betterweb/node:${{steps.parse_version.outputs.PARSED_VERSION}} | |
betterweb/node:${{matrix.tag.major}} |