-
Notifications
You must be signed in to change notification settings - Fork 4
110 lines (87 loc) · 3.38 KB
/
oas-to-sdk-pr.yaml
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
name: Create Pull Request in NodeJS SDK
on:
push:
branches:
- main
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout OAS repository
uses: actions/checkout@v3
- name: Checkout nodejs-sdk repository
uses: actions/checkout@v3
with:
repository: "neynarxyz/nodejs-sdk.git"
ref: "main"
path: "nodejs-sdk"
token: ${{ secrets.OAS_TO_SDK_FGPAT }}
submodules: recursive
persist-credentials: true
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ">=19.9.0"
- name: Update OAS submodule and package version in nodejs-sdk
run: |
cd nodejs-sdk
yarn install
# Update OAS submodule
git submodule update --remote oas
# Set Git config
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# Parse version from OAS
# Install yq for YAML parsing
sudo wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.24.5/yq_linux_amd64
sudo chmod +x /usr/bin/yq
SDK_VERSION=$(yq e '.info."version"' oas/src/v2/spec.yaml)
echo "SDK Version: $SDK_VERSION"
# Check if SDK_VERSION is empty
if [ -z "$SDK_VERSION" ]; then
echo "Error: version not found in OAS file."
exit 1
fi
# Set branch name using SDK_VERSION and GITHUB_RUN_ID
BRANCH_NAME="update-oas-v${SDK_VERSION}-${GITHUB_RUN_ID}"
echo "Branch Name: $BRANCH_NAME"
# Export variables for use in subsequent steps
echo "SDK_VERSION=$SDK_VERSION" >> $GITHUB_ENV
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
# Create and checkout the new branch
git checkout -b "$BRANCH_NAME"
# Commit updated OAS submodule
git add .
git commit -m "Update OAS submodule"
# Generate code
yarn generate:all
# Commit generated files
git add .
git commit -m "Update generated files"
# Update package.json version
npm version --no-git-tag-version "$SDK_VERSION"
# Commit updated package.json
git add package.json
git commit -m "Update package.json version to $SDK_VERSION"
# Push changes
git push origin HEAD:"$BRANCH_NAME"
shell: bash
- name: Create Pull Request via API
run: |
# Install jq for JSON parsing
sudo apt-get update && sudo apt-get install -y jq
# Prepare JSON payload for the pull request
DATA=$(jq -n \
--arg title "Update OAS submodule to version $SDK_VERSION" \
--arg head "$BRANCH_NAME" \
--arg base "main" \
--arg body "This pull request updates the OAS submodule to include the latest changes." \
'{title: $title, head: $head, base: $base, body: $body}')
echo "Creating Pull Request with data: $DATA"
# Create the pull request via GitHub API
curl -X POST \
-H "Authorization: token ${{ secrets.OAS_TO_SDK_FGPAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/neynarxyz/nodejs-sdk/pulls \
-d "$DATA"
shell: bash