-
Notifications
You must be signed in to change notification settings - Fork 3
138 lines (125 loc) · 5.52 KB
/
on-push-master.yml
File metadata and controls
138 lines (125 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: On Push to Master
on:
push:
branches: [master]
paths:
- 'v20111101/**'
- 'v20250224/**'
repository_dispatch:
types: [automated_push_to_master]
jobs:
# Check for skip-publish flag in commit message. This allows skipping publish/release for specific scenarios,
# such as testing generated code, migrating files to new paths, etc.
check-skip-publish:
runs-on: ubuntu-latest
outputs:
skip_publish: ${{ steps.check.outputs.skip_publish }}
steps:
- name: Check for [skip-publish] flag in commit message
id: check
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
if [[ "$COMMIT_MSG" == *"[skip-publish]"* ]]; then
echo "skip_publish=true" >> $GITHUB_OUTPUT
echo "🚫 [skip-publish] flag detected - skipping all publish/release jobs"
else
echo "skip_publish=false" >> $GITHUB_OUTPUT
echo "✅ No skip flag - proceeding with publish/release"
fi
# Detect which API versions were modified.
# Two strategies based on event type:
# - repository_dispatch: Read versions directly from the dispatch payload (api_versions).
# This is reliable because openapi-generate-and-push.yml knows exactly which versions
# it generated and passes them through. Using dorny/paths-filter for dispatch events
# is unreliable (no before/after SHAs, falls back to "last commit" mode which can
# misdetect changes depending on git history and shallow clone depth).
# - push: Use dorny/paths-filter which works correctly with push event before/after SHAs.
detect-changes:
runs-on: ubuntu-latest
outputs:
v20111101: ${{ steps.dispatch-changes.outputs.v20111101 || steps.filter.outputs.v20111101 }}
v20250224: ${{ steps.dispatch-changes.outputs.v20250224 || steps.filter.outputs.v20250224 }}
steps:
# For repository_dispatch: trust the payload from openapi-generate-and-push
- name: Parse dispatch payload
id: dispatch-changes
if: github.event_name == 'repository_dispatch'
run: |
API_VERSIONS="${{ github.event.client_payload.api_versions }}"
echo "Dispatch payload api_versions: $API_VERSIONS"
# Default all versions to false
echo "v20111101=false" >> $GITHUB_OUTPUT
echo "v20250224=false" >> $GITHUB_OUTPUT
# Set true for each version in the payload
for VERSION in $(echo "$API_VERSIONS" | tr ',' ' '); do
echo "${VERSION}=true" >> $GITHUB_OUTPUT
echo " Detected version: $VERSION"
done
# For push events: use dorny/paths-filter (works correctly with push before/after SHAs)
- uses: actions/checkout@v3
if: github.event_name == 'push'
- uses: dorny/paths-filter@v2
if: github.event_name == 'push'
id: filter
with:
filters: |
v20111101:
- 'v20111101/**'
v20250224:
- 'v20250224/**'
# Publish and release for each version conditionally
# Only runs if [skip-publish] flag is NOT present AND files for that version were modified
publish-v20111101:
needs: [check-skip-publish, detect-changes]
if: needs.check-skip-publish.outputs.skip_publish == 'false' && needs.detect-changes.outputs.v20111101 == 'true'
uses: ./.github/workflows/publish.yml
with:
version_directory: v20111101
secrets: inherit
release-v20111101:
needs: [check-skip-publish, detect-changes, publish-v20111101]
if: needs.check-skip-publish.outputs.skip_publish == 'false' && needs.detect-changes.outputs.v20111101 == 'true'
uses: ./.github/workflows/release.yml
with:
version_directory: v20111101
secrets: inherit
delay-for-v20250224:
runs-on: ubuntu-latest
needs: [check-skip-publish, detect-changes]
if: needs.check-skip-publish.outputs.skip_publish == 'false'
steps:
- name: Brief delay to stagger v20250224 publish
run: sleep 2
publish-v20250224:
needs: [check-skip-publish, detect-changes, delay-for-v20250224]
if: needs.check-skip-publish.outputs.skip_publish == 'false' && needs.detect-changes.outputs.v20250224 == 'true'
uses: ./.github/workflows/publish.yml
with:
version_directory: v20250224
secrets: inherit
release-v20250224:
needs: [check-skip-publish, detect-changes, publish-v20250224]
if: needs.check-skip-publish.outputs.skip_publish == 'false' && needs.detect-changes.outputs.v20250224 == 'true'
uses: ./.github/workflows/release.yml
with:
version_directory: v20250224
secrets: inherit
# Notify on failure of orchestration jobs (check-skip-publish, detect-changes, delay).
# Publish and release workflows have their own Slack notifications, so we only
# monitor the jobs owned by this workflow to avoid double-alerting.
slack-notification:
runs-on: ubuntu-latest
needs: [check-skip-publish, detect-changes, delay-for-v20250224]
if: always() && (needs.check-skip-publish.result == 'failure' || needs.detect-changes.result == 'failure' || needs.delay-for-v20250224.result == 'failure')
steps:
- name: Slack notification
uses: ravsamhq/notify-slack-action@v2
with:
status: failure
token: ${{ secrets.GITHUB_TOKEN }}
notification_title: "{repo}: {workflow} workflow"
message_format: "{emoji} *<{workflow_url}|{workflow}>* {status_message} in <{repo_url}|{repo}>"
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}