Skip to content

Commit 6304d3f

Browse files
committed
Use latest api-spec build artifact for proto conversion
Signed-off-by: xil <fridalu66@gmail.com>
1 parent de32498 commit 6304d3f

1 file changed

Lines changed: 63 additions & 18 deletions

File tree

.github/workflows/convert-proto.yml

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,76 @@ jobs:
3232
distribution: temurin
3333
java-version: 17
3434

35-
- name: Download Release Assets
36-
uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f # v1
37-
with:
38-
repository: 'opensearch-project/opensearch-api-specification'
39-
latest: true
40-
fileName: 'opensearch-openapi.yaml'
41-
tag: 'main-latest'
42-
preRelease: true
43-
44-
- name: Get Latest Commit ID
45-
id: get_commit
35+
- name: Resolve API spec build artifact
36+
id: api_spec_artifact
4637
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
4738
with:
4839
github-token: ${{ secrets.GITHUB_TOKEN }}
4940
script: |
5041
const owner = "opensearch-project";
5142
const repo = "opensearch-api-specification";
52-
const commits = await github.rest.repos.listCommits({
43+
const workflow_id = "build.yml";
44+
const branch = "main";
45+
46+
const response = await github.rest.actions.listWorkflowRuns({
5347
owner,
5448
repo,
55-
sha: "main",
49+
workflow_id,
50+
branch,
51+
event: "push",
52+
status: "completed",
5653
per_page: 1
5754
});
58-
const latestCommit = commits.data[0].sha;
59-
core.setOutput("latest_commit", latestCommit);
60-
console.log("Latest commit: " + latestCommit);
55+
const selectedRun = response.data.workflow_runs[0];
56+
57+
if (!selectedRun) {
58+
core.setFailed("Could not find a completed api-spec build run on main.");
59+
return;
60+
}
61+
62+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
63+
owner,
64+
repo,
65+
run_id: selectedRun.id
66+
});
67+
const selectedArtifact = artifacts.data.artifacts.find(
68+
(artifact) => artifact.name === "build" && !artifact.expired
69+
);
70+
71+
if (!selectedArtifact) {
72+
core.setFailed(`Latest completed api-spec build run ${selectedRun.id} does not have a non-expired build artifact.`);
73+
return;
74+
}
75+
76+
core.setOutput("source_commit", selectedRun.head_sha);
77+
core.setOutput("run_id", String(selectedRun.id));
78+
core.setOutput("run_conclusion", selectedRun.conclusion || "unknown");
79+
core.setOutput("artifact_id", String(selectedArtifact.id));
80+
core.setOutput("artifact_download_url", selectedArtifact.archive_download_url);
81+
console.log(
82+
`Using build artifact ${selectedArtifact.id} from run ${selectedRun.id} (${selectedRun.conclusion}) at commit ${selectedRun.head_sha}`
83+
);
84+
85+
- name: Download API spec build artifact
86+
env:
87+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
run: |
89+
curl -L \
90+
-H "Authorization: Bearer $GH_TOKEN" \
91+
-H "Accept: application/vnd.github+json" \
92+
-o api-spec-build.zip \
93+
"${{ steps.api_spec_artifact.outputs.artifact_download_url }}"
94+
95+
rm -rf api-spec-build
96+
unzip -q api-spec-build.zip -d api-spec-build
97+
98+
SPEC_PATH=$(find api-spec-build -name opensearch-openapi.yaml -print -quit)
99+
if [ -z "$SPEC_PATH" ]; then
100+
echo "Could not find opensearch-openapi.yaml in downloaded artifact"
101+
exit 1
102+
fi
103+
104+
cp "$SPEC_PATH" opensearch-openapi.yaml
61105
62106
- name: Get Latest OpenSearch Core Version
63107
id: get_opensearch_version
@@ -164,7 +208,7 @@ jobs:
164208
token: ${{ secrets.GITHUB_TOKEN }}
165209
branch: auto-pr-branch
166210
commit-message: "Protobuf schema change detected"
167-
title: "[Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.get_commit.outputs.latest_commit }})"
211+
title: "[Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.api_spec_artifact.outputs.source_commit }})"
168212
signoff: true
169213
base: main
170214
delete-branch: true
@@ -173,7 +217,8 @@ jobs:
173217
This pull request was automatically generated by GitHub Actions.
174218
175219
**OpenSearch Version**: ${{ steps.get_opensearch_version.outputs.version }}
176-
**API Spec Commit**: ${{ steps.get_commit.outputs.latest_commit }}
220+
**API Spec Commit**: ${{ steps.api_spec_artifact.outputs.source_commit }}
221+
**API Spec Build Run**: ${{ steps.api_spec_artifact.outputs.run_id }} (${{ steps.api_spec_artifact.outputs.run_conclusion }})
177222
178223
---
179224

0 commit comments

Comments
 (0)