Skip to content

chore: 🐝 Update SDK - Generate OUTPOST-GO 1.0.0 (#862) #26

chore: 🐝 Update SDK - Generate OUTPOST-GO 1.0.0 (#862)

chore: 🐝 Update SDK - Generate OUTPOST-GO 1.0.0 (#862) #26

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@v4
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