Skip to content

fix commit issues

fix commit issues #21

Workflow file for this run

---
name: Add-on CI/CD
on:
push:
tags:
- '*'
branches:
- "*"
pull_request:
branches:
- "main"
jobs:
discover:
name: Discover Add-ons
runs-on: ubuntu-latest
outputs:
addon_dirs: ${{ steps.folders.outputs.addon_dirs }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Find add-on directories
id: folders
run: |
ADDON_DIRS=$(find addons -mindepth 1 -maxdepth 1 -type d | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "Found add-on directories: $ADDON_DIRS"
echo "addon_dirs=$ADDON_DIRS" >> $GITHUB_OUTPUT
- name: Debug - List directories
run: |
echo "Found add-on directories: ${{ steps.folders.outputs.addon_dirs }}"
information:
name: Gather add-on information
needs: discover
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.discover.outputs.addon_dirs) }}
outputs:
addon_dirs: ${{ needs.discover.outputs.addon_dirs }}
architectures: ${{ steps.information.outputs.architectures }}
build: ${{ steps.information.outputs.build }}
description: ${{ steps.information.outputs.description }}
name: ${{ steps.information.outputs.name }}
slug: ${{ steps.information.outputs.slug }}
target: ${{ steps.information.outputs.target }}
version: ${{ steps.read_version.outputs.version }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure all tags are fetched
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Run add-on information action
id: information
uses: frenck/action-addon-information@v1
with:
path: "./${{ matrix.folder }}"
- name: Read version from version.txt
id: read_version
run: |
VERSION=$(cat ./${{ matrix.folder }}/version.txt)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Ensure version is 'dev-versionnumber' for branches
if: github.ref != 'refs/heads/main'
run: |
VERSION=$(cat ./${{ matrix.folder }}/version.txt)
jq --arg version "dev-$VERSION" '.version = $version' ./${{ matrix.folder }}/config.json > tmp.json && mv tmp.json ./${{ matrix.folder }}/config.json
- name: Ensure version is correct for main
if: github.ref == 'refs/heads/main'
run: |
VERSION=$(cat ./${{ matrix.folder }}/version.txt)
jq --arg version "$VERSION" '.version = $version' ./${{ matrix.folder }}/config.json > tmp.json && mv tmp.json ./${{ matrix.folder }}/config.json
- name: Update build.json
run: |
VERSION=$(cat ./${{ matrix.folder }}/version.txt)
jq --arg version "$VERSION" '.args.BUILD_VERSION = $version' ./${{ matrix.folder }}/build.json > tmp.json && mv tmp.json ./${{ matrix.folder }}/build.json
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add ./${{ matrix.folder }}/config.json ./${{ matrix.folder }}/build.json
git commit -m "Update version in config and build files"
git pull origin ${{ github.ref }}
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}
- name: Debug - List extracted information
run: |
echo "Architectures: ${{ steps.information.outputs.architectures }}"
echo "Build: ${{ steps.information.outputs.build }}"
echo "Description: ${{ steps.information.outputs.description }}"
echo "Name: ${{ steps.information.outputs.name }}"
echo "Slug: ${{ steps.information.outputs.slug }}"
echo "Target: ${{ steps.information.outputs.target }}"
echo "Version: ${{ steps.read_version.outputs.version }}"
lint-hadolint:
name: Hadolint
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
needs: information
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.information.outputs.addon_dirs) }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Run Hadolint
uses: brpaz/hadolint-action@v1.5.0
with:
dockerfile: "./${{ matrix.folder }}/Dockerfile"
config: .hadolint.yaml
lint-json:
name: JSON Lint
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
needs: information
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.information.outputs.addon_dirs) }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Run JQ
run: |
shopt -s globstar
cat ./${{ matrix.folder }}/**/*.json | jq '.'
lint-shellcheck:
name: Shellcheck
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
needs: information
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.information.outputs.addon_dirs) }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Run Shellcheck
uses: ludeeus/action-shellcheck@2.0.0
env:
SHELLCHECK_OPTS: -s bash
lint-yamllint:
name: YAMLLint
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
needs: information
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.information.outputs.addon_dirs) }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Run YAMLLint
uses: frenck/action-yamllint@v1.5
with:
config: .yamllint
lint-prettier:
name: Prettier
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
needs: information
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.information.outputs.addon_dirs) }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Debug - Print addon_dirs
run: |
echo "addon_dirs: ${{ needs.information.outputs.addon_dirs }}"
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Run Prettier
uses: creyD/prettier_action@v4.3
with:
prettier_options: --write ./${{ matrix.folder }}/**/*.{json,js,md,yaml}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add ./${{ matrix.folder }}/config.json ./${{ matrix.folder }}/build.json
if ! git diff-index --quiet HEAD; then
git commit -m "Prettified Code!"
git fetch origin
git rebase origin/${{ github.ref }}
if [ $? -ne 0 ]; then
echo "Rebase failed, attempting to resolve conflicts"
git rebase --abort
git pull origin ${{ github.ref }}
fi
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}
else
echo "No changes to commit"
fi
build_main_or_pr:
name: Build ${{ matrix.architecture }} (Main or PR)
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request')
needs:
information
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
architecture: ["aarch64", "amd64", "armhf", "armv7", "i386"]
folder: ${{ fromJson(needs.information.outputs.addon_dirs || '["addons/example"]') }}
outputs:
version: ${{ steps.set_version.outputs.version }}
slug_lower: ${{ steps.convert.outputs.slug_lower }}
repository_owner_lower: ${{ steps.convert.outputs.repository_owner_lower }}
folder: ${{ matrix.folder }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v3
- name: Set version for branches
id: set_version
run: |
VERSION=${{ needs.information.outputs.version }}
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
VERSION="dev-${VERSION}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Set up build cache
id: cache
uses: actions/cache@v4.0.2
with:
path: /tmp/.docker-cache
key: docker-${{ matrix.architecture }}-${{ github.sha }}
restore-keys: |
docker-${{ matrix.architecture }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.0.0
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.3.0
- name: Compose build flags
id: flags
run: |
echo "date=$(date '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
from=$(yq eval '.build_from["${{ matrix.architecture }}"]' "${{ needs.information.outputs.build }}")
from=$(echo $from | tr -d '"')
echo "from=${from}" >> $GITHUB_OUTPUT
echo "BUILD_VERSION=${{ needs.information.outputs.version }}" >> $GITHUB_OUTPUT
if [[ "${{ matrix.architecture }}" == "amd64" ]]; then
echo "platform=linux/amd64" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "i386" ]]; then
echo "platform=linux/386" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "armhf" ]]; then
echo "platform=linux/arm/v6" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "armv7" ]]; then
echo "platform=linux/arm/v7" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "aarch64" ]]; then
echo "platform=linux/arm64/v8" >> $GITHUB_OUTPUT
else
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
exit 1
fi
- name: Debug - Print 'from' variable
run: |
echo "From variable: ${{ steps.flags.outputs.from }}"
- name: Download base image
if: steps.flags.outputs.from != 'null'
run: |
echo "Pulling base image: ${{ steps.flags.outputs.from }}"
docker pull ${{ steps.flags.outputs.from }}
- name: Convert to Lowercase
id: convert
run: |
SLUG_LOWER=$(echo ${{ needs.information.outputs.slug }} | tr '[:upper:]' '[:lower:]')
REPOSITORY_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
REPOSITORY_OWNER_LOWER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
echo "slug_lower=$SLUG_LOWER" >> $GITHUB_OUTPUT
echo "repository_lower=$REPOSITORY_LOWER" >> $GITHUB_OUTPUT
echo "repository_owner_lower=$REPOSITORY_OWNER_LOWER" >> $GITHUB_OUTPUT
- name: Build and Push Docker image
uses: docker/build-push-action@v2
with:
push: true
context: ./${{ matrix.folder }}
file: ./${{ matrix.folder }}/Dockerfile
platforms: ${{ steps.flags.outputs.platform }}
cache-from: type=local,src=/tmp/.docker-cache
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new
build-args: |
BUILD_ARCH=${{ matrix.architecture }}
BUILD_DATE=${{ steps.flags.outputs.date }}
BUILD_DESCRIPTION=${{ needs.information.outputs.description }}
BUILD_FROM=${{ steps.flags.outputs.from }}
BUILD_NAME=${{ needs.information.outputs.name }}
BUILD_REF=${{ github.sha }}
BUILD_REPOSITORY=${{ steps.convert.outputs.repository_lower }}
BUILD_VERSION=${{ needs.information.outputs.version }}
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ steps.convert.outputs.slug_lower }}:${{ steps.set_version.outputs.version }}-${{ matrix.architecture }}
- name: Swap build cache
run: |
if [ -d /tmp/.docker-cache-new ]; then
rm -rf /tmp/.docker-cache
mv /tmp/.docker-cache-new /tmp/.docker-cache
else
echo "Cache directory /tmp/.docker-cache-new does not exist"
fi
build_other_branches:
name: Build ${{ matrix.architecture }} (Other Branches)
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
needs:
- information
- lint-hadolint
- lint-json
- lint-shellcheck
- lint-yamllint
- lint-prettier
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
architecture: ["aarch64", "amd64", "armhf", "armv7", "i386"]
folder: ${{ fromJson(needs.information.outputs.addon_dirs || '["addons/example"]') }}
outputs:
version: ${{ steps.set_version.outputs.version }}
slug_lower: ${{ steps.convert.outputs.slug_lower }}
repository_owner_lower: ${{ steps.convert.outputs.repository_owner_lower }}
folder: ${{ matrix.folder }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v3
- name: Set version for branches
id: set_version
run: |
VERSION=${{ needs.information.outputs.version }}
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
VERSION="dev-${VERSION}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Debug - Print matrix folder path
run: |
echo "Matrix folder path: ${{ matrix.folder }}"
- name: Set up build cache
id: cache
uses: actions/cache@v4.0.2
with:
path: /tmp/.docker-cache
key: docker-${{ matrix.architecture }}-${{ github.sha }}
restore-keys: |
docker-${{ matrix.architecture }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.0.0
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.3.0
- name: Compose build flags
id: flags
run: |
echo "date=$(date '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
from=$(yq eval '.build_from["${{ matrix.architecture }}"]' "${{ needs.information.outputs.build }}")
from=$(echo $from | tr -d '"')
echo "from=${from}" >> $GITHUB_OUTPUT
echo "BUILD_VERSION=${{ needs.information.outputs.version }}" >> $GITHUB_OUTPUT
if [[ "${{ matrix.architecture }}" == "amd64" ]]; then
echo "platform=linux/amd64" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "i386" ]]; then
echo "platform=linux/386" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "armhf" ]]; then
echo "platform=linux/arm/v6" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "armv7" ]]; then
echo "platform=linux/arm/v7" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.architecture }}" == "aarch64" ]]; then
echo "platform=linux/arm64/v8" >> $GITHUB_OUTPUT
else
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
exit 1
fi
- name: Debug - Print 'from' variable
run: |
echo "From variable: ${{ steps.flags.outputs.from }}"
- name: Download base image
if: steps.flags.outputs.from != 'null'
run: |
echo "Pulling base image: ${{ steps.flags.outputs.from }}"
docker pull ${{ steps.flags.outputs.from }}
- name: Convert to Lowercase
id: convert
run: |
SLUG_LOWER=$(echo ${{ needs.information.outputs.slug }} | tr '[:upper:]' '[:lower:]')
REPOSITORY_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
REPOSITORY_OWNER_LOWER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
echo "slug_lower=$SLUG_LOWER" >> $GITHUB_OUTPUT
echo "repository_lower=$REPOSITORY_LOWER" >> $GITHUB_OUTPUT
echo "repository_owner_lower=$REPOSITORY_OWNER_LOWER" >> $GITHUB_OUTPUT
- name: Build and Push Docker image
uses: docker/build-push-action@v2
with:
push: true
context: ./${{ matrix.folder }}
file: ./${{ matrix.folder }}/Dockerfile
platforms: ${{ steps.flags.outputs.platform }}
cache-from: type=local,src=/tmp/.docker-cache
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new
build-args: |
BUILD_ARCH=${{ matrix.architecture }}
BUILD_DATE=${{ steps.flags.outputs.date }}
BUILD_DESCRIPTION=${{ needs.information.outputs.description }}
BUILD_FROM=${{ steps.flags.outputs.from }}
BUILD_NAME=${{ needs.information.outputs.name }}
BUILD_REF=${{ github.sha }}
BUILD_REPOSITORY=${{ steps.convert.outputs.repository_lower }}
BUILD_VERSION=${{ needs.information.outputs.version }}
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ steps.convert.outputs.slug_lower }}:${{ steps.set_version.outputs.version }}-${{ matrix.architecture }}
- name: Swap build cache
run: |
if [ -d /tmp/.docker-cache-new ]; then
rm -rf /tmp/.docker-cache
mv /tmp/.docker-cache-new /tmp/.docker-cache
else
echo "Cache directory /tmp/.docker-cache-new does not exist"
fi
create_and_push_manifest_latest:
name: Create and Push Docker Manifest
runs-on: ubuntu-latest
needs: build_main_or_pr
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create and Push Docker Manifest latest
run: |
IMAGE_NAME="${{ secrets.DOCKER_USERNAME }}/${{ needs.build_main_or_pr.outputs.slug_lower }}"
VERSION="${{ needs.build_main_or_pr.outputs.version }}"
docker buildx imagetools create \
-t $IMAGE_NAME:latest \
$IMAGE_NAME:$VERSION-amd64 \
$IMAGE_NAME:$VERSION-aarch64 \
$IMAGE_NAME:$VERSION-armhf \
$IMAGE_NAME:$VERSION-i386 \
$IMAGE_NAME:$VERSION-armv7
- name: Create and Push Docker Manifest Version
run: |
IMAGE_NAME="${{ secrets.DOCKER_USERNAME }}/${{ needs.build_main_or_pr.outputs.slug_lower }}"
VERSION="${{ needs.build_main_or_pr.outputs.version }}"
docker buildx imagetools create \
-t $IMAGE_NAME:$VERSION \
$IMAGE_NAME:$VERSION-amd64 \
$IMAGE_NAME:$VERSION-aarch64 \
$IMAGE_NAME:$VERSION-armhf \
$IMAGE_NAME:$VERSION-i386 \
$IMAGE_NAME:$VERSION-armv7
create_and_push_manifest_dev:
name: Create and Push Docker Manifest
runs-on: ubuntu-latest
needs: build_other_branches
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create and Push Docker Manifest dev
run: |
IMAGE_NAME="${{ secrets.DOCKER_USERNAME }}/${{ needs.build_other_branches.outputs.slug_lower }}"
VERSION="${{ needs.build_other_branches.outputs.version }}"
docker buildx imagetools create \
-t $IMAGE_NAME:DEV \
$IMAGE_NAME:$VERSION-amd64 \
$IMAGE_NAME:$VERSION-aarch64 \
$IMAGE_NAME:$VERSION-armhf \
$IMAGE_NAME:$VERSION-i386 \
$IMAGE_NAME:$VERSION-armv7
- name: Create and Push Docker Manifest version
run: |
IMAGE_NAME="${{ secrets.DOCKER_USERNAME }}/${{ needs.build_other_branches.outputs.slug_lower }}"
VERSION="${{ needs.build_other_branches.outputs.version }}"
docker buildx imagetools create \
-t $IMAGE_NAME:$VERSION \
$IMAGE_NAME:$VERSION-amd64 \
$IMAGE_NAME:$VERSION-aarch64 \
$IMAGE_NAME:$VERSION-armhf \
$IMAGE_NAME:$VERSION-i386 \
$IMAGE_NAME:$VERSION-armv7
update_config_main_or_pr:
runs-on: ubuntu-latest
needs: build_main_or_pr
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up jq
run: sudo apt-get install jq
- name: Update config.json with new image URL
run: |
IMAGE_URL="docker.io/${{ secrets.DOCKER_USERNAME }}/${{ needs.build_main_or_pr.outputs.slug_lower }}"
jq --arg image "$IMAGE_URL" '.image = $image' ./${{ needs.build_main_or_pr.outputs.folder }}/config.json > tmp.json && mv tmp.json ./${{ needs.build_main_or_pr.outputs.folder }}/config.json
- name: Update build.json with build date
run: |
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
jq --arg date "$BUILD_DATE" '.args.BUILD_DATE = $date' ./${{ needs.build_main_or_pr.outputs.folder }}/build.json > tmp.json && mv tmp.json ./${{ needs.build_main_or_pr.outputs.folder }}/build.json
- name: Commit and push updated config.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |

Check failure on line 565 in .github/workflows/CI-CD.yaml

View workflow run for this annotation

GitHub Actions / Add-on CI/CD

Invalid workflow file

The workflow is not valid. .github/workflows/CI-CD.yaml (Line: 565, Col: 16): Unexpected symbol: 'ref#refs/heads/'. Located at position 8 within expression: github.ref#refs/heads/ .github/workflows/CI-CD.yaml (Line: 604, Col: 16): Unexpected symbol: 'ref#refs/heads/'. Located at position 8 within expression: github.ref#refs/heads/

Check failure on line 565 in .github/workflows/CI-CD.yaml

View workflow run for this annotation

GitHub Actions / Add-on CI/CD

Invalid workflow file

The workflow is not valid. .github/workflows/CI-CD.yaml (Line: 565, Col: 16): Unexpected symbol: 'ref#refs/heads/'. Located at position 8 within expression: github.ref#refs/heads/ .github/workflows/CI-CD.yaml (Line: 604, Col: 16): Unexpected symbol: 'ref#refs/heads/'. Located at position 8 within expression: github.ref#refs/heads/
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add ./${{ needs.build_other_branches.outputs.folder }}/config.json
git add ./${{ needs.build_other_branches.outputs.folder }}/build.json
if git diff-index --quiet HEAD; then
echo "No changes to commit"
else
git fetch origin
git rebase origin/${{ github.ref#refs/heads/ }}
if [ $? -ne 0 ]; then
echo "Rebase failed, attempting to resolve conflicts"
git rebase --abort
git pull origin ${{ github.ref#refs/heads/ }}
fi
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref#refs/heads/ }}
fi
update_config_other_branches:
runs-on: ubuntu-latest
needs: build_other_branches
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up jq
run: sudo apt-get install jq
- name: Update config.json with new image URL
run: |
IMAGE_URL="docker.io/${{ secrets.DOCKER_USERNAME }}/${{ needs.build_other_branches.outputs.slug_lower }}"
jq --arg image "$IMAGE_URL" '.image = $image' ./${{ needs.build_other_branches.outputs.folder }}/config.json > tmp.json && mv tmp.json ./${{ needs.build_other_branches.outputs.folder }}/config.json
- name: Update build.json with build date
run: |
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
jq --arg date "$BUILD_DATE" '.args.DEV_BUILD_DATE = $date' ./${{ needs.build_other_branches.outputs.folder }}/build.json > tmp.json && mv tmp.json ./${{ needs.build_other_branches.outputs.folder }}/build.json
- name: Commit and push updated config.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add ./${{ needs.build_other_branches.outputs.folder }}/config.json
git add ./${{ needs.build_other_branches.outputs.folder }}/build.json
if git diff-index --quiet HEAD; then
echo "No changes to commit"
else
git fetch origin
git rebase origin/${{ github.ref#refs/heads/ }}
if [ $? -ne 0 ]; then
echo "Rebase failed, attempting to resolve conflicts"
git rebase --abort
git pull origin ${{ github.ref#refs/heads/ }}
fi
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref#refs/heads/ }}
fi