-
Notifications
You must be signed in to change notification settings - Fork 41
158 lines (136 loc) · 5.77 KB
/
sdk_publish_outpost_go.yaml
File metadata and controls
158 lines (136 loc) · 5.77 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
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Publish OUTPOST-GO
permissions:
checks: write
contents: write
pull-requests: write
statuses: write
id-token: write
"on":
push:
branches:
- main
paths:
- sdks/outpost-go/.speakeasy/gen.lock
workflow_dispatch: {}
jobs:
publish:
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15
with:
target: outpost-go
secrets:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
update_shields_and_commit:
needs: publish
if: needs.publish.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Ensure all tags are fetched
- name: Install yq
run: |
sudo apt-get update && sudo apt-get install -y yq
shell: bash
- name: Get Go SDK Version from gen.yaml
id: get_version
run: |
GEN_YAML_PATH="sdks/outpost-go/.speakeasy/gen.yaml"
if [ ! -f "$GEN_YAML_PATH" ]; then
echo "Error: $GEN_YAML_PATH not found."
exit 1
fi
# Read the version using yq; ensure it's not empty or literal "null"
SDK_VERSION_RAW=$(yq -r '.go.version' "$GEN_YAML_PATH")
if [ -z "$SDK_VERSION_RAW" ] || [ "$SDK_VERSION_RAW" = "null" ]; then
echo "Error: Could not read .go.version from $GEN_YAML_PATH, or version is null/empty."
echo "Content of $GEN_YAML_PATH:"
cat "$GEN_YAML_PATH"
exit 1
fi
echo "Go SDK version from $GEN_YAML_PATH: $SDK_VERSION_RAW"
echo "sdk_version=$SDK_VERSION_RAW" >> $GITHUB_OUTPUT
shell: bash
- name: Debug Information
env:
PUBLISH_VERSION: ${{ steps.get_version.outputs.sdk_version }}
run: |
echo "Go SDK version from gen.yaml: $PUBLISH_VERSION"
- name: Update shields.json
env:
NEW_VERSION: ${{ steps.get_version.outputs.sdk_version }} # This will be like "0.2.1"
run: |
echo "Updating shields.json with version from gen.yaml: $NEW_VERSION"
SHIELD_VERSION_VALUE=$NEW_VERSION # e.g., 0.2.1
# Ensure it starts with 'v' for the shield
if [[ ! $SHIELD_VERSION_VALUE == v* ]]; then
SHIELD_VERSION_VALUE="v$SHIELD_VERSION_VALUE" # e.g., v0.2.1
fi
echo "Formatted shield version for JSON: $SHIELD_VERSION_VALUE"
SHIELDS_FILE="sdks/outpost-go/shields.json"
TEMP_SHIELDS_FILE=$(mktemp)
if [ ! -f "$SHIELDS_FILE" ]; then
echo "Error: $SHIELDS_FILE not found."
exit 1
fi
jq --arg version "$SHIELD_VERSION_VALUE" '.message = $version' "$SHIELDS_FILE" > "$TEMP_SHIELDS_FILE"
if [ $? -ne 0 ] || [ ! -s "$TEMP_SHIELDS_FILE" ]; then
echo "Error: jq command failed or produced an empty file."
echo "Original $SHIELDS_FILE content:"
cat "$SHIELDS_FILE"
echo "Temporary file content (if any):"
cat "$TEMP_SHIELDS_FILE"
rm -f "$TEMP_SHIELDS_FILE"
exit 1
fi
mv "$TEMP_SHIELDS_FILE" "$SHIELDS_FILE"
echo "Updated $SHIELDS_FILE content:"
cat "$SHIELDS_FILE"
- name: Create Pull Request for shields.json update
env:
NEW_VERSION: ${{ steps.get_version.outputs.sdk_version }} # This will be like "0.2.1"
GH_TOKEN: ${{ github.token }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
SHIELDS_FILE="sdks/outpost-go/shields.json"
if [ ! -f "$SHIELDS_FILE" ]; then
echo "Error: $SHIELDS_FILE not found."
exit 1
fi
# Determine version for commit message and branch name
# NEW_VERSION is the raw version from gen.yaml, e.g., "0.2.1"
COMMIT_MSG_VERSION_PART=$NEW_VERSION
# Ensure it starts with 'v' for commit messages, branch names, PR titles
if [[ ! $COMMIT_MSG_VERSION_PART == v* ]]; then
COMMIT_MSG_VERSION_PART="v$COMMIT_MSG_VERSION_PART" # e.g., v0.2.1
fi
BRANCH_NAME="chore/update-go-shields-$COMMIT_MSG_VERSION_PART"
COMMIT_MESSAGE="chore(sdk): update outpost-go shields.json to version $COMMIT_MSG_VERSION_PART"
PR_TITLE="Chore(sdk): Update outpost-go shields.json to version $COMMIT_MSG_VERSION_PART"
PR_BODY=$(cat <<EOF
This PR updates the \`sdks/outpost-go/shields.json\` file to version $COMMIT_MSG_VERSION_PART.
This change was triggered by the automated workflow based on the version in \`sdks/outpost-go/.speakeasy/gen.yaml\`: \`$NEW_VERSION\`.
EOF
)
# Create a new branch or reset if it already exists locally
git checkout -B "$BRANCH_NAME"
git add "$SHIELDS_FILE"
if git diff --staged --quiet; then
echo "No changes to commit in $SHIELDS_FILE. Branch $BRANCH_NAME will not be created or pushed."
else
echo "Committing changes to $SHIELDS_FILE..."
git commit -m "$COMMIT_MESSAGE"
echo "Pushing branch $BRANCH_NAME..."
git push origin "$BRANCH_NAME"
echo "Creating Pull Request..."
gh pr create \
--base main \
--head "$BRANCH_NAME" \
--title "$PR_TITLE" \
--body "$PR_BODY"
echo "Pull Request created for branch $BRANCH_NAME."
fi
shell: bash