|
19 | 19 | IMAGE_NAME: ${{ github.repository }} |
20 | 20 |
|
21 | 21 | jobs: |
| 22 | + # Check if this is a template repository or a consuming repository |
| 23 | + check-repo-type: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + is-template: ${{ steps.check.outputs.is-template }} |
| 27 | + should-publish: ${{ steps.check.outputs.should-publish }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Check repository type |
| 34 | + id: check |
| 35 | + run: | |
| 36 | + # Check if this is a template repository by looking for template indicators |
| 37 | + # Template repositories typically have specific patterns in their files |
| 38 | + if [[ "${{ github.repository }}" == "droq-ai/dfx-base-node-template-py" ]]; then |
| 39 | + echo "is-template=true" >> $GITHUB_OUTPUT |
| 40 | + echo "should-publish=false" >> $GITHUB_OUTPUT |
| 41 | + echo "::notice::This is the template repository - Docker publishing is disabled" |
| 42 | + elif grep -q "droq-node-template" README.md 2>/dev/null && \ |
| 43 | + grep -q "Replace src/node/main.py with your code" README.md 2>/dev/null; then |
| 44 | + echo "is-template=true" >> $GITHUB_OUTPUT |
| 45 | + echo "should-publish=false" >> $GITHUB_OUTPUT |
| 46 | + echo "::notice::Template repository detected - Docker publishing is disabled. Consumers should customize before publishing." |
| 47 | + else |
| 48 | + echo "is-template=false" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + # Determine if should publish based on event |
| 51 | + if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]] || \ |
| 52 | + [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]] || \ |
| 53 | + [[ "${{ github.event.inputs.publish }}" == "true" ]]; then |
| 54 | + echo "should-publish=true" >> $GITHUB_OUTPUT |
| 55 | + echo "::notice::Consuming repository detected - Docker publishing is enabled" |
| 56 | + else |
| 57 | + echo "should-publish=false" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | + fi |
| 60 | +
|
22 | 61 | build-and-test: |
23 | 62 | runs-on: ubuntu-latest |
| 63 | + needs: check-repo-type |
24 | 64 | outputs: |
25 | 65 | image-digest: ${{ steps.build.outputs.digest }} |
26 | 66 | image-tag: ${{ steps.meta.outputs.tags }} |
27 | | - should-publish: ${{ steps.should-publish.outputs.result }} |
| 67 | + should-publish: ${{ needs.check-repo-type.outputs.should-publish }} |
28 | 68 |
|
29 | 69 | steps: |
30 | 70 | - name: Checkout repository |
|
46 | 86 | type=semver,pattern={{major}} |
47 | 87 | type=raw,value=latest,enable={{is_default_branch}} |
48 | 88 |
|
49 | | - - name: Determine if should publish |
50 | | - id: should-publish |
51 | | - run: | |
52 | | - if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]] || \ |
53 | | - [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]] || \ |
54 | | - [[ "${{ github.event.inputs.publish }}" == "true" ]]; then |
55 | | - echo "result=true" >> $GITHUB_OUTPUT |
56 | | - else |
57 | | - echo "result=false" >> $GITHUB_OUTPUT |
58 | | - fi |
59 | | -
|
60 | 89 | - name: Build Docker image |
61 | 90 | id: build |
62 | 91 | uses: docker/build-push-action@v5 |
|
73 | 102 |
|
74 | 103 | publish: |
75 | 104 | runs-on: ubuntu-latest |
76 | | - needs: build-and-test |
| 105 | + needs: [check-repo-type, build-and-test] |
77 | 106 | if: needs.build-and-test.outputs.should-publish == 'true' |
78 | 107 | environment: production |
79 | 108 |
|
@@ -131,7 +160,7 @@ jobs: |
131 | 160 |
|
132 | 161 | publish-private-registry: |
133 | 162 | runs-on: ubuntu-latest |
134 | | - needs: build-and-test |
| 163 | + needs: [check-repo-type, build-and-test] |
135 | 164 | if: needs.build-and-test.outputs.should-publish == 'true' && secrets.PRIVATE_REGISTRY_URL != '' |
136 | 165 | environment: production |
137 | 166 |
|
@@ -174,7 +203,7 @@ jobs: |
174 | 203 |
|
175 | 204 | security-scan: |
176 | 205 | runs-on: ubuntu-latest |
177 | | - needs: [build-and-test, publish] |
| 206 | + needs: [check-repo-type, build-and-test, publish] |
178 | 207 | if: needs.build-and-test.outputs.should-publish == 'true' |
179 | 208 | environment: production |
180 | 209 |
|
|
0 commit comments