|
| 1 | +name: build apps |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + workflow_run: |
| 5 | + workflows: [build base] |
| 6 | + types: [completed] |
| 7 | + branches: |
| 8 | + - master |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - master |
| 12 | + paths: |
| 13 | + - apps/** |
| 14 | + - scripts/apps/** |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + packages: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + check_changes: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + apps_json: ${{ steps.emit.outputs.apps_json }} |
| 24 | + steps: |
| 25 | + - if: ${{ github.event_name == 'push' }} |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - if: ${{ github.event_name == 'push' }} |
| 31 | + id: filter |
| 32 | + uses: dorny/paths-filter@v3 |
| 33 | + with: |
| 34 | + filters: | |
| 35 | + postgresql_changed: |
| 36 | + - 'apps/postgresql/**' |
| 37 | + - 'scripts/apps/postgresql/**' |
| 38 | + uptime_kuma_2_changed: |
| 39 | + - 'apps/uptime-kuma-2/**' |
| 40 | + - 'scripts/apps/uptime-kuma-2/**' |
| 41 | + base_changed: |
| 42 | + - 'base/**' |
| 43 | + - 'scripts/base/ampstart.sh' |
| 44 | +
|
| 45 | + - id: emit |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + # Default matrix when not a push: build all apps |
| 50 | + if [ "${{ github.event_name }}" != "push" ]; then |
| 51 | + echo 'apps_json=["postgresql","uptime-kuma-2"]' >> "$GITHUB_OUTPUT" |
| 52 | + exit 0 |
| 53 | + fi |
| 54 | +
|
| 55 | + # On push: if base changed, build nothing (let base workflow handle rebuilds) |
| 56 | + if [ "${{ steps.filter.outputs.base_changed || 'false' }}" = "true" ]; then |
| 57 | + echo 'apps_json=[]' >> "$GITHUB_OUTPUT" |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | +
|
| 61 | + apps=() |
| 62 | + if [ "${{ steps.filter.outputs.postgresql_changed || 'false' }}" = "true" ]; then apps+=('"postgresql"'); fi |
| 63 | + if [ "${{ steps.filter.outputs.uptime_kuma_2_changed || 'false' }}" = "true" ]; then apps+=('"uptime-kuma-2"'); fi |
| 64 | +
|
| 65 | + if [ "${#apps[@]}" -eq 0 ]; then |
| 66 | + echo 'apps_json=[]' >> "$GITHUB_OUTPUT" |
| 67 | + else |
| 68 | + printf 'apps_json=[%s]\n' "$(IFS=,; echo "${apps[*]}")" >> "$GITHUB_OUTPUT" |
| 69 | + fi |
| 70 | +
|
| 71 | + build_and_push: |
| 72 | + needs: [check_changes] |
| 73 | + if: ${{ github.repository_owner == 'CubeCoders' && github.ref == 'refs/heads/master' && (github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success') }} |
| 74 | + name: 'amp:apps-${{ matrix.app }}' |
| 75 | + runs-on: ubuntu-latest |
| 76 | + strategy: |
| 77 | + fail-fast: false |
| 78 | + matrix: |
| 79 | + app: ${{ fromJSON(needs.check_changes.outputs.apps_json) }} |
| 80 | + |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }} |
| 85 | + |
| 86 | + - uses: docker/setup-qemu-action@v3 |
| 87 | + - uses: docker/setup-buildx-action@v3 |
| 88 | + |
| 89 | + - uses: docker/login-action@v3 |
| 90 | + with: |
| 91 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 92 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 93 | + |
| 94 | + - uses: docker/build-push-action@v6 |
| 95 | + with: |
| 96 | + context: . |
| 97 | + file: ./apps/${{ matrix.app }}/Dockerfile |
| 98 | + platforms: linux/amd64,linux/arm64/v8 |
| 99 | + push: true |
| 100 | + pull: true |
| 101 | + tags: cubecoders/ampbase:${{ matrix.app }} |
| 102 | + cache-from: type=registry,ref=cubecoders/ampbase:${{ matrix.app }} |
| 103 | + cache-to: type=inline |
| 104 | + provenance: mode=max |
| 105 | + sbom: true |
| 106 | + |
| 107 | +concurrency: |
| 108 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 109 | + cancel-in-progress: false |
0 commit comments