Build Nushell Release Images #62
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 Nushell Release Images | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- docker | |
schedule: | |
- cron: '15 2 * * 2,5' # Run at 02:15 AM UTC for Tuesday and Friday | |
workflow_dispatch: | |
jobs: | |
build-and-push-Nu: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: | |
base: [debian, alpine] | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: Set up Nushell | |
uses: hustcer/setup-nu@v3 | |
with: | |
check-latest: true | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Set tag & labels for ${{ github.ref }}" | |
shell: nu {0} | |
run: | | |
let tagName = http get https://api.github.com/repos/nushell/nushell/releases | |
| sort-by -r created_at | select tag_name | get tag_name.0 | |
git remote set-url origin https://github.com/nushell/nushell.git | |
git fetch origin -p o+e> /dev/null | |
let SHA = git rev-list -n 1 $tagName | str substring 0..7 | |
$'BUILD_REF=($SHA)(char nl)' o>> $env.GITHUB_ENV | |
$'NU_VERSION=($tagName)(char nl)' o>> $env.GITHUB_ENV | |
$'BUILD_DATE=(date now | format date %Y-%m-%dT%H:%M:%SZ)(char nl)' o>> $env.GITHUB_ENV | |
- name: Build Debian Test Image | |
uses: docker/build-push-action@v6 | |
if: ${{ matrix.base == 'debian' }} | |
env: | |
DOCKER_BUILD_SUMMARY: false | |
with: | |
push: false | |
load: true | |
context: ./docker | |
file: ./docker/debian.Dockerfile | |
tags: nushell-debian-test-image | |
- name: Test Debian Image | |
if: ${{ matrix.base == 'debian' }} | |
run: | | |
echo "## Debian Container Test Results" >> $GITHUB_STEP_SUMMARY | |
docker run --rm \ | |
-v "$(pwd)/docker:/work" \ | |
--env GITHUB_ACTIONS=${{ env.GITHUB_ACTIONS }} \ | |
nushell-debian-test-image -c /work/test_docker.nu \ | |
>> $GITHUB_STEP_SUMMARY | |
- name: Build and Push Debian Image | |
uses: docker/build-push-action@v6 | |
if: ${{ matrix.base == 'debian' }} | |
with: | |
push: true | |
provenance: false | |
context: ./docker | |
file: ./docker/debian.Dockerfile | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
# platforms: linux/amd64,linux/arm64,linux/riscv64 | |
build-args: | | |
BUILD_REF=${{ env.BUILD_REF }} | |
BUILD_DATE=${{ env.BUILD_DATE }} | |
NU_VERSION=${{ env.NU_VERSION }} | |
tags: | | |
ghcr.io/nushell/nushell:latest-bookworm | |
ghcr.io/nushell/nushell:${{ env.NU_VERSION }}-bookworm | |
- name: Build Alpine Test Image | |
uses: docker/build-push-action@v6 | |
if: ${{ matrix.base == 'alpine' }} | |
env: | |
DOCKER_BUILD_SUMMARY: false | |
with: | |
push: false | |
load: true | |
context: ./docker | |
file: ./docker/Dockerfile | |
tags: nushell-alpine-test-image | |
- name: Test Alpine Image | |
if: ${{ matrix.base == 'alpine' }} | |
run: | | |
echo "## Alpine Container Test Results" >> $GITHUB_STEP_SUMMARY | |
docker run --rm \ | |
-v "$(pwd)/docker:/work" \ | |
--env GITHUB_ACTIONS=${{ env.GITHUB_ACTIONS }} \ | |
nushell-alpine-test-image -c /work/test_docker.nu \ | |
>> $GITHUB_STEP_SUMMARY | |
- name: Build and Push Alpine Image | |
uses: docker/build-push-action@v6 | |
if: ${{ matrix.base == 'alpine' }} | |
with: | |
push: true | |
provenance: false | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
context: ./docker | |
file: ./docker/Dockerfile | |
build-args: | | |
BUILD_REF=${{ env.BUILD_REF }} | |
BUILD_DATE=${{ env.BUILD_DATE }} | |
NU_VERSION=${{ env.NU_VERSION }} | |
tags: | | |
ghcr.io/nushell/nushell:latest | |
ghcr.io/nushell/nushell:latest-alpine | |
ghcr.io/nushell/nushell:${{ env.NU_VERSION }} | |
ghcr.io/nushell/nushell:${{ env.NU_VERSION }}-alpine | |
cleanup: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: build-and-push-Nu | |
steps: | |
- name: Delete all containers from repository without tags | |
uses: Chizkiyahu/delete-untagged-ghcr-action@v4 | |
with: | |
owner_type: user | |
untagged_only: true | |
package_name: 'nushell' | |
repository_owner: 'nushell' | |
repository: 'nushell/nushell' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
except_untagged_multiplatform: true |