@@ -31,32 +31,72 @@ jobs:
3131 distribution : temurin
3232 java-version : 17
3333
34- - name : Download Release Assets
35- uses : robinraju/release-downloader@v1
36- with :
37- repository : ' opensearch-project/opensearch-api-specification'
38- latest : true
39- fileName : ' opensearch-openapi.yaml'
40- tag : ' main-latest'
41- preRelease : true
42-
43- - name : Get Latest Commit ID
44- id : get_commit
34+ - name : Get Latest Spec Build Run
35+ id : get_spec_build
4536 uses : actions/github-script@v6
4637 with :
4738 github-token : ${{ secrets.GITHUB_TOKEN }}
4839 script : |
4940 const owner = "opensearch-project";
5041 const repo = "opensearch-api-specification";
51- const commits = await github.rest.repos.listCommits ({
42+ const runs = await github.rest.actions.listWorkflowRuns ({
5243 owner,
5344 repo,
54- sha: "main",
55- per_page: 1
45+ workflow_id: "build.yml",
46+ branch: "main",
47+ event: "push",
48+ per_page: 20
5649 });
57- const latestCommit = commits.data[0].sha;
58- core.setOutput("latest_commit", latestCommit);
59- console.log("Latest commit: " + latestCommit);
50+
51+ const latestSuccessfulRun = runs.data.workflow_runs.find(
52+ (run) => run.conclusion === "success"
53+ );
54+
55+ if (!latestSuccessfulRun) {
56+ core.setFailed("Could not find a successful build.yml workflow run on main.");
57+ return;
58+ }
59+
60+ core.setOutput("run_id", String(latestSuccessfulRun.id));
61+ core.setOutput("head_sha", latestSuccessfulRun.head_sha);
62+ console.log("Latest successful build run: " + latestSuccessfulRun.id);
63+ console.log("Spec commit: " + latestSuccessfulRun.head_sha);
64+
65+ - name : Download Latest Spec Build Artifact
66+ id : download_build_artifact
67+ uses : actions/download-artifact@v5
68+ with :
69+ name : build
70+ path : spec-build
71+ github-token : ${{ secrets.API_SPEC_ACTIONS_READ_TOKEN || github.token }}
72+ repository : opensearch-project/opensearch-api-specification
73+ run-id : ${{ steps.get_spec_build.outputs.run_id }}
74+ continue-on-error : true
75+
76+ - name : Download Latest Spec Release Asset Fallback
77+ if : steps.download_build_artifact.outcome != 'success'
78+ uses : robinraju/release-downloader@v1
79+ with :
80+ repository : ' opensearch-project/opensearch-api-specification'
81+ latest : true
82+ fileName : ' opensearch-openapi.yaml'
83+ tag : ' main-latest'
84+ preRelease : true
85+
86+ - name : Prepare OpenAPI Spec Source
87+ run : |
88+ SPEC_FILE=""
89+ if [ -d spec-build ]; then
90+ SPEC_FILE=$(find spec-build -maxdepth 3 -name 'opensearch-openapi.yaml' -print | head -n 1)
91+ fi
92+ if [ -z "$SPEC_FILE" ]; then
93+ SPEC_FILE=$(find . -maxdepth 3 -name 'opensearch-openapi.yaml' -print | head -n 1)
94+ fi
95+ if [ -z "$SPEC_FILE" ]; then
96+ echo "Could not locate opensearch-openapi.yaml from the spec source."
97+ exit 1
98+ fi
99+ cp "$SPEC_FILE" opensearch-openapi.yaml
60100
61101 - name : Get Latest OpenSearch Core Version
62102 id : get_opensearch_version
@@ -163,7 +203,7 @@ jobs:
163203 token : ${{ secrets.GITHUB_TOKEN }}
164204 branch : auto-pr-branch
165205 commit-message : " Protobuf schema change detected"
166- title : " [Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.get_commit .outputs.latest_commit }})"
206+ title : " [Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.get_spec_build .outputs.head_sha }})"
167207 signoff : true
168208 base : main
169209 delete-branch : true
@@ -172,7 +212,7 @@ jobs:
172212 This pull request was automatically generated by GitHub Actions.
173213
174214 **OpenSearch Version**: ${{ steps.get_opensearch_version.outputs.version }}
175- **API Spec Commit**: ${{ steps.get_commit .outputs.latest_commit }}
215+ **API Spec Commit**: ${{ steps.get_spec_build .outputs.head_sha }}
176216
177217 ---
178218
0 commit comments