Update ci.yml #17
This file contains hidden or 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: ci | |
on: | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- synchronize | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.prepare.outputs.matrix }} | |
length: ${{ steps.prepare.outputs.length }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
since_last_remote_commit: true | |
separator: "\\n" | |
files: | | |
**/* | |
- name: Echo list of changed files on success | |
run: | | |
echo "Changed files:" | |
echo "${{ steps.changed-files.outputs.all_changed_files }}" | |
- name: Prepare | |
id: prepare | |
shell: python | |
run: | | |
import json | |
import os | |
from pathlib import Path | |
from typing import Any, Generator | |
def discover() -> Generator[str, Any, None]: | |
for changed in "${{ steps.changed-files.outputs.all_changed_files }}".split("\n"): | |
print(changed) | |
path = Path(changed) | |
if Path(path.parts[0]).is_dir(): | |
yield path.parts[0] | |
def jsonify(item_lists: dict[str,list[str]]) -> str: | |
return json.dumps(item_lists, separators=(",", ":")) | |
def main() -> None: | |
item_lists = list(set(discover())) | |
print() | |
length = len(item_lists) | |
json_modules = jsonify({"service": item_lists}) | |
github_output = f"matrix={json_modules}\n" | |
print(github_output) | |
print(length) | |
with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
f.write(github_output) | |
f.write(f"length={length}\n") | |
if __name__ == "__main__": | |
main() | |
- name: Echo prepare step output | |
run: | | |
echo "Changed files length:" | |
echo "${{ steps.prepare.outputs.length }}" | |
echo "Changed files:" | |
echo '${{ fromJson(steps.prepare.outputs.matrix) }}' | |
build: | |
needs: prepare | |
runs-on: ubuntu-latest | |
if: false #${{ needs.prepare.outputs.length > 0 }} | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- 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: | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
- id: meta | |
name: Docker metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }}/${{ matrix.service }} | |
- id: build-push | |
name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: ${{ matrix.service }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
${{ steps.meta.outputs.tags }} |