add basic of notify/dependent build #126
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 Docker image | |
on: | |
workflow_dispatch: | |
inputs: | |
path: | |
required: false | |
type: string | |
default: "" | |
push: | |
branches: | |
- main | |
registry_package: | |
env: | |
REGISTRY: ghcr.io | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
attestations: write | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.changed-dockerfiles.outputs.all_changed_files }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get changed Dockerfiles | |
id: changed-dockerfiles | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: | | |
**/Dockerfile | |
matrix: true | |
- name: List all changed files | |
run: echo '${{ steps.changed-dockerfiles.outputs.all_changed_files }}' | |
run-matrix: | |
needs: prepare | |
if: ${{ needs.prepare.outputs.matrix != '[]' }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dockerfile: ${{ fromJSON(needs.prepare.outputs.matrix) }} | |
max-parallel: 4 | |
fail-fast: false | |
steps: | |
- name: Set image_name variable | |
run: | | |
echo "dockerfile=${{ matrix.dockerfile }}" >> $GITHUB_ENV | |
dir_name=$(dirname "${{ matrix.dockerfile }}") | |
echo "dir_name=$dir_name" >> $GITHUB_ENV | |
image_name="yettoapp/${dir_name//\//-}" | |
echo "image_name=$image_name" >> $GITHUB_ENV | |
- uses: yettoapp/images/.github/actions/publish-to-ghcr@main | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
run-trigger: | |
if: ${{ inputs.path != '' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set image_name variable | |
run: | | |
echo "dockerfile=${{ inputs.path }}/Dockerfile" >> $GITHUB_ENV | |
dir_name=$(dirname "${{ inputs.path }}/Dockerfile") | |
echo "dir_name=$dir_name" >> $GITHUB_ENV | |
image_name="yettoapp/${dir_name//\//-}" | |
echo "image_name=$image_name" >> $GITHUB_ENV | |
- uses: yettoapp/images/.github/actions/publish-to-ghcr@main | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
dependent: | |
if: ${{ github.event_name == 'registry_package' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check publication type | |
run: | | |
if [ "${{ github.event.registry_package.package_type }}" != "container" ]; then | |
echo "This is not a container package" | |
exit 0 | |
fi | |
- name: Send GitHub Action data to a Slack workflow | |
uses: slackapi/[email protected] | |
with: | |
payload-delimiter: "_" | |
webhook: ${{ secrets.SLACK_INFRA_WEBHOOK_URL }} | |
webhook-type: webhook-trigger | |
- name: Set name of dependent image | |
run: | | |
package_name="${{ github.event.registry_package.name }}" | |
dependent = "" | |
valid_names=("base-ruby" "base-rails") | |
if [[ " ${valid_names[@]} " =~ " ${package_name} " ]]; then | |
dependent = "app/plug/ruby" | |
fi | |
echo "dockerfile=$dependent/Dockerfile" >> $GITHUB_ENV | |
dir_name=$(dirname "$dependent/Dockerfile") | |
echo "dir_name=$dir_name" >> $GITHUB_ENV | |
image_name="yettoapp/${dir_name//\//-}" | |
echo "image_name=$image_name" >> $GITHUB_ENV | |
- uses: yettoapp/images/.github/actions/publish-to-ghcr@main | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |