From ee1a7064defb6d31c3136e80e1ecdd15695f4d67 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 6 Mar 2024 22:27:46 +0100 Subject: [PATCH] feat: move scripts logic to actions --- .github/workflows/main.yml | 191 ++++++++++++++++++++++++++----------- ohmyzsh/.dockerignore | 1 - ohmyzsh/build.sh | 27 ------ zsh/.dockerignore | 1 - zsh/build.sh | 20 ---- 5 files changed, 134 insertions(+), 106 deletions(-) delete mode 100755 ohmyzsh/build.sh delete mode 100755 zsh/build.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fb61c9c..1a7c936 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,76 +1,153 @@ name: Publish Docker images on: workflow_dispatch: {} + push: + branches: + - main + pull_request: schedule: - cron: "46 2 * * 1" +env: + LATEST_ZSH: "5.9" + DOCKERHUB_ORG: "ohmyzsh" + MAIN_OMZ_BRANCH: "master" # TODO: we need to change master with main when migrating the branch + jobs: - build-and-push: - name: Build Docker images + get-omz-versions: + name: Get Oh My Zsh versions runs-on: ubuntu-latest + outputs: + versions: ${{ steps.versions.outputs.versions }} steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Build images - env: - zsh_tags: | - master - 5.9 - 5.8.1 - 5.8 - 5.7.1 - 5.7 - 5.6.2 - 5.6.1 - 5.6 - 5.5.1 - 5.5 - 5.4.2 - 5.4.1 - 5.4 - 5.3.1 - 5.3 - 5.2 - 5.1.1 - 5.1 - 5.0.8 - 5.0.7 - 5.0.6 - 5.0.5 - 5.0.4 - 5.0.3 - 5.0.2 - 5.0.1 - 5.0.0 - 4.3.17 - 4.3.16 - 4.3.15 - 4.3.14 - 4.3.13 - 4.3.12 - 4.3.11 + - name: Get Oh My Zsh versions + id: versions run: | - for image in */Dockerfile; do - image="$(basename $(dirname $image))" + OMZ_VERSIONS=$(curl -sL https://api.github.com/repos/ohmyzsh/ohmyzsh/tags | jq -c '["${{ env.MAIN_OMZ_BRANCH }}",.[].name]') + echo "versions=$OMZ_VERSIONS" >> $GITHUB_OUTPUT - if ! test -f "$image/build.sh"; then - echo "::error ::missing build.sh file at /$image" - exit 1 - fi + build-omz: + name: Build Oh My Zsh Docker image + runs-on: ubuntu-latest + needs: + - get-omz-versions + strategy: + matrix: + omz-version: ${{ fromJSON(needs.get-omz-versions.outputs.versions) }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Get tags and versions + id: tags + run: | + tags=${{ env.DOCKERHUB_ORG }}/ohmyzsh:${{ matrix.omz-version }} + if [ ${{matrix.omz-version }} = ${{ env.MAIN_OMZ_BRANCH }} ]; then + tags="${tags},${{ env.DOCKERHUB_ORG }}/ohmyzsh:latest" + fi + echo "tags=$tags" >> $GITHUB_OUTPUT + - name: Build and push images + uses: docker/build-push-action@v5 + with: + context: ohmyzsh + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + build-args: "OMZ_VERSION=${{ matrix.omz-version }}" + tags: ${{ steps.tags.outputs.tags }} - "$image/build.sh" ${{ secrets.DOCKERHUB_ORG }} - done + build-zsh: + name: Build Zsh Docker images + runs-on: ubuntu-latest + strategy: + matrix: + zsh-version: + - "master" + - "5.9" + - "5.8.1" + - "5.8" + - "5.7.1" + - "5.7" + - "5.6.2" + - "5.6.1" + - "5.6" + - "5.5.1" + - "5.5" + - "5.4.2" + - "5.4.1" + - "5.4" + - "5.3.1" + - "5.3" + - "5.2" + - "5.1.1" + - "5.1" + - "5.0.8" + - "5.0.7" + - "5.0.6" + - "5.0.5" + - "5.0.4" + - "5.0.3" + - "5.0.2" + - "5.0.1" + - "5.0.0" + - "4.3.17" + - "4.3.16" + - "4.3.15" + - "4.3.14" + - "4.3.13" + - "4.3.12" + - "4.3.11" + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 - name: Log in to Docker Hub - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Push to Docker Hub + - name: Get tags and versions + id: tags run: | - for image in */Dockerfile; do - image="$(basename $(dirname $image))" - docker push "${{ secrets.DOCKERHUB_ORG }}/$image" --all-tags - done + tags=${{ env.DOCKERHUB_ORG }}/zsh:${{ matrix.zsh-version }} + if [ ${{matrix.zsh-version }} = ${{ env.LATEST_ZSH }} ]; then + tags="${tags},${{ env.DOCKERHUB_ORG }}/zsh:latest" + fi + echo "tags=$tags" >> $GITHUB_OUTPUT + - name: Build and push images + uses: docker/build-push-action@v5 + with: + context: zsh + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + build-args: "ZSH_VERSION=${{ matrix.zsh-version }}" + tags: ${{ steps.tags.outputs.tags }} + + update-image-readme: + needs: + - build-zsh + - build-omz + runs-on: ubuntu-latest + if: ${{ github.event_name != 'pull_request' }} + steps: - name: Update image READMEs env: DH_USERNAME: ${{ secrets.DOCKERHUB_USER }} @@ -84,5 +161,5 @@ jobs: continue fi - node .github/scripts/update-image-readme.js "${{ secrets.DOCKERHUB_ORG }}/$image" "$image/README.md" + node .github/scripts/update-image-readme.js "${{ env.DOCKERHUB_ORG }}/$image" "$image/README.md" done diff --git a/ohmyzsh/.dockerignore b/ohmyzsh/.dockerignore index 4b60fd2..b43bf86 100644 --- a/ohmyzsh/.dockerignore +++ b/ohmyzsh/.dockerignore @@ -1,2 +1 @@ -build.sh README.md diff --git a/ohmyzsh/build.sh b/ohmyzsh/build.sh deleted file mode 100755 index 57ded00..0000000 --- a/ohmyzsh/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Enter the directory -cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 - -# Get image username -USERNAME="$1" -# Get image from directory name -IMAGE="$(basename "$(pwd)")" - -# Get ohmyzsh stable releases -versions="$(curl -sL https://api.github.com/repos/ohmyzsh/ohmyzsh/tags | sed -n 's/[^0-9.]*"name": "v\?\([^"]*\)"[^0-9.]*/\n\1/g;s/^\n//p')" -versions="$versions main" - -# Build images -for version in $versions; do - # Rename main to master for the branch name - # TODO: remove this logic once the master branch has been renamed - omz_version=$version - [[ $version = main ]] && omz_version=master - - docker buildx build -t "$USERNAME/$IMAGE:$version" --build-arg OMZ_VERSION="$omz_version" . -done - -# Tag latest image -latest=$(tr ' ' '\n' <<< "$versions" | sed '/^$/d' | sort -V | tail -2 | head -1) -docker tag "$USERNAME/$IMAGE:$latest" "$USERNAME/$IMAGE:latest" diff --git a/zsh/.dockerignore b/zsh/.dockerignore index 4b60fd2..b43bf86 100644 --- a/zsh/.dockerignore +++ b/zsh/.dockerignore @@ -1,2 +1 @@ -build.sh README.md diff --git a/zsh/build.sh b/zsh/build.sh deleted file mode 100755 index 2bfd712..0000000 --- a/zsh/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Enter the directory -cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 - -# Get image username -USERNAME="$1" -# Get image from directory name -IMAGE="$(basename "$(pwd)")" - -# $zsh_tags is an environment variable passed via secrets - -# Build images -for version in $zsh_tags; do - docker buildx build -t "$USERNAME/$IMAGE:$version" --build-arg ZSH_VERSION="$version" . -done - -# Tag latest image -latest=$(tr ' ' '\n' <<< "$zsh_tags" | sed '/^$/d' | sort -V | tail -2 | head -1) -docker tag "$USERNAME/$IMAGE:$latest" "$USERNAME/$IMAGE:latest"