-
Notifications
You must be signed in to change notification settings - Fork 13
145 lines (120 loc) · 4.46 KB
/
deploy-openapi-assets.yml
File metadata and controls
145 lines (120 loc) · 4.46 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
139
140
141
142
143
144
145
name: Deploy Openapi Assets
on:
push:
branches: [main, feat-openapi-package]
paths:
- "packages/openapi/**"
jobs:
pack:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
outputs:
version: ${{ steps.set-outputs.outputs.version }}
packfile_name: ${{ steps.set-outputs.outputs.packfile_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- id: set-outputs
name: Pack @docs/openapi and upload artifacts
run: |
set -euo pipefail
cd packages/openapi
echo "Working dir: $(pwd)"
cat package.json
npm ci
# npm pack prints the filename; grab the last non-empty line
PACKFILE=$(npm pack | sed -n '/./p' | tail -n1)
echo "Packed file: $PACKFILE"
# create stable 'latest' name
LATEST_NAME="openapi-latest.tgz"
cp -f "$PACKFILE" "$LATEST_NAME"
# ensure files exist
ls -la
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "packfile_name=$PACKFILE" >> "$GITHUB_OUTPUT"
- name: Upload tarballs as artifact
uses: actions/upload-artifact@v4
with:
name: openapi-tarballs
path: |
packages/openapi/${{ steps.set-outputs.outputs.packfile_name }}
packages/openapi/openapi-latest.tgz
release-openapi-packages:
runs-on: ubuntu-latest
needs: pack
environment: production
permissions:
contents: write
steps:
- name: Checkout (needed for workspace)
uses: actions/checkout@v4
- name: Download packed artifacts
uses: actions/download-artifact@v4
with:
name: openapi-tarballs
path: artifacts
- name: Show artifacts (debug)
run: ls -la artifacts || true
- name: Resolve artifact paths
id: find
run: |
set -euo pipefail
PACKFILE="${{ needs.pack.outputs.packfile_name }}"
PACK_PATH=$(find artifacts -type f -name "$PACKFILE" -print -quit || true)
LATEST_PATH=$(find artifacts -type f -name "openapi-latest.tgz" -print -quit || true)
echo "Found pack path: $PACK_PATH"
echo "Found latest path: $LATEST_PATH"
if [ -z "$PACK_PATH" ] || [ -z "$LATEST_PATH" ]; then
echo "::error::Missing artifact(s). Debug listing:"
ls -Rla artifacts || true
exit 1
fi
echo "pack_path=$PACK_PATH" >> "$GITHUB_OUTPUT"
echo "latest_path=$LATEST_PATH" >> "$GITHUB_OUTPUT"
- name: Ensure GH CLI available
run: gh --version || (echo "gh not installed" && exit 1)
- name: Upload versioned asset (replace if exists)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="openapi-v${{ needs.pack.outputs.version }}"
ASSET="artifacts/${{ needs.pack.outputs.packfile_name }}"
# create release if missing
if ! gh release view "$TAG" >/dev/null 2>&1; then
gh release create "$TAG" --title "OpenAPI v${{ needs.pack.outputs.version }}" --notes "Automated release"
fi
# upload and overwrite existing asset with same name
gh release upload "$TAG" "$ASSET" --clobber
- name: Upload latest asset (replace if exists)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_TAG="openapi-latest"
LATEST_ASSET="artifacts/openapi-latest.tgz"
if ! gh release view "$LATEST_TAG" >/dev/null 2>&1; then
gh release create "$LATEST_TAG" --title "OpenAPI (latest)" --notes "Automated latest release"
fi
gh release upload "$LATEST_TAG" "$LATEST_ASSET" --clobber
rebuild-schema:
runs-on: ubuntu-latest
environment: production
needs:
- release-openapi-packages
steps:
- name: Trigger autoupdate swagger
env:
GH_ORG_ACCESS_TOKEN: ${{ secrets.GH_ORG_ACCESS_TOKEN }}
OPENAPI_REPO: ${{ secrets.OPENAPI_REPO }}
run: |
curl -X POST \
-H "Authorization: Bearer $GH_ORG_ACCESS_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$OPENAPI_REPO/dispatches \
-d '{"event_type":"api-docs-release"}'