forked from opensearch-project/opensearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Thomas Farr <[email protected]>
- Loading branch information
Showing
5 changed files
with
1,067 additions
and
925 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
name: Code Generation | ||
|
||
on: [pull_request] | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 * * 1' # 00:00 UTC Weekly on Mondays | ||
|
||
env: | ||
is_opensearch_repo: ${{ github.repository == 'opensearch-project/opensearch-java' }} | ||
is_schedule: ${{ github.event_name == 'schedule' }} | ||
update_to_latest: ${{ env.is_schedule == 'true' || github.event_name == 'workflow_dispatch' }} | ||
|
||
jobs: | ||
up_to_date: | ||
name: Ensure Generated Code Up To Date | ||
if: env.is_schedule != 'true' || env.is_opensearch_repo == 'true' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout Java Client | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
|
@@ -17,18 +32,53 @@ jobs: | |
distribution: 'temurin' | ||
cache: 'gradle' | ||
|
||
- name: Download Latest Spec | ||
if: env.update_to_latest == 'true' | ||
run: ./gradlew :java-codegen:downloadLatestSpec | ||
|
||
- name: Run Code Generator | ||
run: ./gradlew clean :java-codegen:run | ||
run: ./gradlew :java-codegen:run | ||
|
||
- name: Check Has No Changes | ||
- name: Git Status | ||
id: status | ||
shell: bash -eo pipefail {0} | ||
run: | | ||
echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | ||
output=$(git status --porcelain) | ||
if [ -z "$output" ]; then | ||
echo "Clean working directory" | ||
exit 0 | ||
echo "clean=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "Dirty working directory" | ||
echo "$output" | ||
exit 1 | ||
fi | ||
echo "clean=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Fail On Uncommitted Changes | ||
if: env.update_to_latest != 'true' && steps.status.outputs.clean != 'true' | ||
run: exit 1 | ||
|
||
- name: Generate GitHub App Token | ||
if: env.is_opensearch_repo == 'true' && env.update_to_latest == 'true' && steps.status.outputs.clean != 'true' | ||
id: github_app_token | ||
uses: tibdex/[email protected] | ||
with: | ||
app_id: ${{ secrets.APP_ID }} | ||
private_key: ${{ secrets.APP_PRIVATE_KEY }} | ||
installation_id: 22958780 | ||
|
||
- name: Create Pull Request | ||
if: env.update_to_latest == 'true' && steps.status.outputs.clean != 'true' | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ steps.github_app_token.outputs.token || secrets.GITHUB_TOKEN }} | ||
commit-message: Re-generate client code using latest OpenSearch API specification (${{ steps.status.outputs.date }}) | ||
title: Re-generated client code using latest OpenSearch API specification | ||
body: | | ||
Re-generated client code using latest OpenSearch API specification. | ||
Date: ${{ steps.status.outputs.date }} | ||
branch: code-gen/${{ github.ref_name }}/update | ||
signoff: true | ||
labels: | | ||
autocut |
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
Oops, something went wrong.