Generate Go SDK #865
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Generate Go SDK" | |
on: | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
# Run generation nightly on latest OpenAPI spec | |
- cron: '0 0 * * *' | |
jobs: | |
cloud-builds: | |
strategy: | |
matrix: | |
platform: [dotcom, ghec] | |
fail-fast: false | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.x.x' | |
- uses: actions/setup-go@v3.5.0 | |
with: | |
go-version: '1.21.5' | |
- name: Set repository name from platform for later use | |
run: | | |
if [ "${{ matrix.platform }}" == "dotcom" ]; then | |
echo "REPO_NAME=go-sdk" >> $GITHUB_ENV | |
else | |
echo "REPO_NAME=go-sdk-enterprise-cloud" >> $GITHUB_ENV | |
fi | |
- name: Run scripts/generate-go.sh | |
run: scripts/generate-go.sh ${{ matrix.platform }} | |
- name: Clone the existing repository | |
run: | | |
cd ../ | |
git clone https://github.com/octokit/$REPO_NAME.git | |
- name: Copy generated code to downstream repository | |
run: | | |
cp -rf stage/go/$REPO_NAME/. ../$REPO_NAME/ #copy everything | |
rsync -av --delete stage/go/$REPO_NAME/pkg/ ../$REPO_NAME/pkg/ # delete files that are not generated | |
- uses: gr2m/create-or-update-pull-request-action@cd-path | |
if: github.event_name != 'pull_request' # do not update the SDK on PR builds | |
env: | |
GITHUB_TOKEN: ${{ secrets.OCTOKITBOT_SDK_PAT }} | |
REPO_NAME: ${{ env.REPO_NAME }} | |
with: | |
title: "Changes in generated code" | |
body: > | |
The latest OpenAPI spec resulted in changes to the generated code. Please review, set an applicable | |
commit message, merge, and tag a release as appropriate. | |
branch: "generated-code-update-${{ matrix.platform }}" | |
author: "Octokit Bot <security+octokitbot@github.com>" | |
commit-message: "New updates to generated code" | |
repository: "octokit/${{ env.REPO_NAME }}" | |
path-to-cd-to: "../${{ env.REPO_NAME }}" | |
server-builds: | |
strategy: | |
matrix: | |
version: ["3.11", "3.12", "3.13", "3.14"] # versions must be quoted or 3.10 becomes 3.1 | |
fail-fast: false | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.x.x' | |
- uses: actions/setup-go@v3.5.0 | |
with: | |
go-version: '1.21.5' | |
- name: Run scripts/generate-go.sh | |
run: scripts/generate-go.sh ghes ${{ matrix.version }} | |
- name: Clone the existing repository and check out appropriate branch (create it if it doesn't exist) | |
run: | | |
cd ../ | |
git clone https://github.com/octokit/go-sdk-enterprise-server.git | |
cd go-sdk-enterprise-server | |
if git show-ref --verify --quiet refs/remotes/origin/${{ matrix.version }}; then | |
git switch -c ${{ matrix.version }} --track origin/${{ matrix.version }} | |
echo "Branch ${{ matrix.version }} already exists; skipping creation and fetching from remote" | |
else | |
git switch -c ${{ matrix.version }} | |
echo "Branch ${{ matrix.version }} does not exist on remote; created locally" | |
git switch - | |
fi | |
cd ../ | |
- name: Copy generated code to downstream repository | |
run: | | |
cp -rf stage/go/go-sdk-enterprise-server/. ../go-sdk-enterprise-server/ # copy everything | |
rsync -av --delete stage/go/go-sdk-enterprise-server/pkg/ ../go-sdk-enterprise-server/pkg/ # delete files that are not generated | |
- uses: gr2m/create-or-update-pull-request-action@cd-path | |
if: github.event_name != 'pull_request' # do not update the SDK on PR builds | |
env: | |
GITHUB_TOKEN: ${{ secrets.OCTOKITBOT_SDK_PAT }} | |
with: | |
title: "GHES ${{ matrix.version}}: Changes in generated code" | |
body: > | |
The latest OpenAPI spec resulted in changes to the generated code. Please review, set an applicable | |
commit message, merge, and tag a release as appropriate. | |
base-branch: ${{ matrix.version }} | |
branch: "generated-code-update-${{ matrix.version }}" | |
author: "Octokit Bot <security+octokitbot@github.com>" | |
commit-message: "New updates to generated code" | |
repository: "octokit/go-sdk-enterprise-server" | |
path-to-cd-to: "../go-sdk-enterprise-server" |