getting closer i think #22
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: Add-on CI/CD | |
on: | |
push: | |
branches: | |
- main | |
- 'feature/**' | |
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: | |
architectures: ${{ steps.information.outputs.architectures }} | |
build: ${{ steps.information.outputs.build }} | |
name: ${{ steps.information.outputs.name }} | |
slug: ${{ steps.information.outputs.slug }} | |
target: ${{ steps.information.outputs.target }} | |
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 add-on information action | |
id: information | |
uses: frenck/action-addon-information@v1 | |
with: | |
path: "./${{ matrix.folder }}" | |
lint-hadolint: | |
name: Hadolint | |
needs: information | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
folder: ${{ fromJson(needs.discover.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/[email protected] | |
with: | |
dockerfile: "./${{ matrix.folder }}/dockerfile" | |
lint-yamllint: | |
name: YAMLLint | |
needs: information | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
folder: ${{ fromJson(needs.discover.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/[email protected] | |
with: | |
path: "./${{ matrix.folder }}" | |
lint-prettier: | |
name: Prettier | |
needs: information | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
folder: ${{ fromJson(needs.discover.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 Prettier | |
uses: creyD/[email protected] | |
with: | |
prettier_options: --write ./${{ matrix.folder }}/**/*.{json,js,md,yaml} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
lint-shellcheck: | |
name: Shellcheck | |
needs: information | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
folder: ${{ fromJson(needs.discover.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/[email protected] | |
env: | |
SHELLCHECK_OPTS: -s bash | |
lint-json: | |
name: JSON Lint | |
needs: information | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
folder: ${{ fromJson(needs.discover.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 '.' | |
build: | |
name: Build ${{ matrix.architecture }} | |
needs: | |
- lint-hadolint | |
- lint-json | |
- lint-shellcheck | |
- lint-yamllint | |
- lint-prettier | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
architecture: ${{ fromJson(needs.information.outputs.architectures) }} | |
folder: ${{ fromJson(needs.information.outputs.folder) }} | |
steps: | |
- name: Check out code from GitHub | |
uses: actions/checkout@v4 | |
- name: Set up build cache | |
id: cache | |
uses: actions/[email protected] | |
with: | |
path: /tmp/.docker-cache | |
key: docker-${{ matrix.architecture }}-${{ github.sha }} | |
restore-keys: | | |
docker-${{ matrix.architecture }} | |
- name: Set up QEMU | |
uses: docker/[email protected] | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Compose build flags | |
id: flags | |
run: | | |
echo "date=$(date +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT | |
from=$(yq --no-colors eval ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}") | |
echo "from=${from}" >> $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 | |
- name: Download base image | |
if: steps.flags.outputs.from != 'null' | |
run: docker pull "${{ steps.flags.outputs.from }}" | |
- name: Build | |
uses: docker/[email protected] | |
with: | |
push: false | |
context: ./${{ matrix.folder }} | |
file: ./${{ matrix.folder }}/Dockerfile | |
cache-from: | | |
type=local,src=/tmp/.docker-cache | |
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge | |
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new | |
platforms: ${{ steps.flags.outputs.platform }} | |
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=${{ github.repository }} | |
BUILD_VERSION=edge | |
- name: Swap build cache | |
run: | | |
rm -rf /tmp/.docker-cache | |
mv /tmp/.docker-cache-new /tmp/.docker-cache | |
publish: | |
name: Publish to Repository | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dispatch repository update signal | |
uses: peter-evans/repository-dispatch@v1 | |
with: | |
token: ${{ secrets.DISPATCH_TOKEN }} | |
repository: ${{ github.repository_owner }}/repository | |
event-type: update | |
client-payload: > | |
{ | |
"addon": "${{ needs.information.outputs.slug }}", | |
"name": "${{ needs.information.outputs.name }}", | |
"repository": "${{ github.repository }}", | |
"version": "edge" | |
} |