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 changed team image | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
find-team-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
modifiedTeams: ${{ steps.filter.outputs.changes }} | |
steps: | |
- name: ↩️ Checkout | |
uses: actions/checkout@v3 | |
- name: 📂 Detect changed team folder | |
uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
filters: | | |
brown_independents: | |
- 'Teams/brown_independents/**' | |
ginger_mariners: | |
- 'Teams/ginger_mariners/**' | |
green_twins: | |
- 'Teams/green_twins/**' | |
pink_hotspurs: | |
- 'Teams/pink_hotspurs/**' | |
purple_saints: | |
- 'Teams/purple_saints/**' | |
red_titans: | |
- 'Teams/red_titans/**' | |
white_dodgers: | |
- 'Teams/white_dodgers/**' | |
yellow_pirates: | |
- 'Teams/yellow_pirates/**' | |
build-team-image: | |
name: Build team docker image | |
if: ${{ needs.find-team-changes.outputs.modifiedTeams != '[]' }} | |
runs-on: ubuntu-latest | |
needs: find-team-changes | |
strategy: | |
fail-fast: false | |
matrix: | |
team: ${{ fromJSON(needs.find-team-changes.outputs.modifiedTeams) }} | |
steps: | |
- name: ↩️ Checkout | |
uses: actions/checkout@v2 | |
- name: 🏗️ Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: ℹ️ Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ghcr.io/hacktoberfestmunich/hacktoberfest-2023 | |
tags: type=raw,value=${{ matrix.team }} | |
- name: 🔑 ghcr Login | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: 💿 Build Image | |
if: ${{ github.event_name != 'push' }} | |
uses: docker/build-push-action@v4 | |
with: | |
context: "Teams/${{ matrix.team }}" | |
push: false | |
file: Teams/${{ matrix.team }}/Dockerfile | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
- name: 🚀 Build and push Image | |
if: ${{ github.event_name == 'push' }} | |
uses: docker/build-push-action@v4 | |
with: | |
context: "Teams/${{ matrix.team }}" | |
push: true | |
file: Teams/${{ matrix.team }}/Dockerfile | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
cleanup-images: | |
name: Cleanup untagged images from ghcr | |
if: ${{ github.event_name == 'push' }} | |
runs-on: ubuntu-latest | |
needs: find-team-changes | |
steps: | |
- name: 🗑️ Cleanup old untagged images | |
uses: dylanratcliffe/[email protected] | |
with: | |
org: ${{ github.repository_owner }} | |
token: ${{ secrets.HACKTOBERFEST2023_PAT }} | |
package_name: 'hacktoberfest-2023' |