Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
feat: update sync workflow to line up with metal-go (#105)
Browse files Browse the repository at this point in the history
The updated sync workflow performs spec fetching, spec patching, and
code generation as separate steps. This enables the workflow to open a
draft PR if some of those steps fail so that any issues that come up
during sync can be addressed with fewer manual steps.

---------

Co-authored-by: equinix-labs@auto-commit-workflow <bot@equinix.noreply.github.com>
  • Loading branch information
ctreatma and equinix-labs@auto-commit-workflow authored Jul 27, 2023
1 parent 753c1f3 commit 9a37829
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 930 deletions.
58 changes: 42 additions & 16 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
on: ["workflow_dispatch"]
name: Sync

on:
workflow_dispatch:

jobs:
sync:
strategy:
Expand All @@ -14,39 +17,62 @@ jobs:
uses: actions/checkout@v3
- name: GitHub user
run: |
# https://api.github.com/users/github-actions[bot]
git config user.name 'github-actions[bot]'
git config user.email 'bot@equinix.noreply.github.com'
- name: Sync
- name: Fetch latest spec
id: fetch
run: |
make fetch
git add spec/oas3.fetched
git commit -m 'sync: fetch ${{ steps.date.outputs.date }} spec' spec/oas3.fetched
echo `git commit -m 'sync: fetch ${{ steps.date.outputs.date }} spec'`
- name: Apply spec patches
id: patch
if: ${{ always() && steps.fetch.conclusion == 'success' }}
run: |
make patch
git add spec/oas3.patched
echo `git commit -m 'sync: apply patches to ${{ steps.date.outputs.date }} spec'`
- name: Generate code
id: generate
if: ${{ always() && steps.patch.conclusion == 'success' }}
run: |
make docker_run
echo -e "Make execution completed."
git add spec/oas3.patched/.
git add spec/oas3.stitched/.
git add equinix-openapi-metal/.
echo -e "\nGit status:"
echo `git status`
cmsg='sync: generate code for ${{ steps.date.outputs.date }} spec'
echo -e "\nCommit message created : $cmsg"
echo -e "\nCommitting if there are files to update in client dir:"
echo `git commit -m "$cmsg"`
make docker_generate move-workflow build_client
git add equinix-openapi-metal
echo `git commit -m 'sync: generate client with patched ${{ steps.date.outputs.date }} spec'`
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
id: cpr
uses: peter-evans/create-pull-request@v5
if: ${{ always() && steps.fetch.conclusion == 'success' }}
with:
branch: sync/gh
branch-suffix: timestamp
title: API Sync by GitHub Action (${{ steps.date.outputs.date }})
author: github-actions[bot] <bot@equinix.noreply.github.com>
commit-message: "sync: uncommitted changes detected when opening PR"
title: "feat: API Sync by GitHub Action (${{ steps.date.outputs.date }})"
body: |
This API Sync PR was automated through [GitHub Actions workflow_displatch](https://github.com/equinix-labs/metal-go/actions?query=event%3Aworkflow_dispatch)
on ${{ steps.date.outputs.date }}.
* latest Swagger is fetched
* patches have been applied
* generated client has been updated
delete-branch: true
draft: ${{ steps.patch.conclusion == 'failure' || steps.generate.conclusion == 'failure' }}
- name: Comment for failed patch
uses: mshick/add-pr-comment@v2
if: ${{ always() && steps.patch.conclusion == 'failure' && steps.cpr.conclusion == 'success' }}
with:
issue: ${{ steps.cpr.outputs.pull-request-number }}
message: Failed to patch latest spec. Someone with write access must fix this PR manually and then convert it from Draft status to Ready for Review.
- name: Comment for failed generate
uses: mshick/add-pr-comment@v2
if: ${{ always() && steps.generate.conclusion == 'failure' && steps.cpr.conclusion == 'success' }}
with:
issue: ${{ steps.cpr.outputs.pull-request-number }}
message: Failed to generate code from latest patched spec. Someone with write access must fix this PR manually and then convert it from Draft status to Ready for Review.
- name: Check outputs
if: ${{ always() && steps.cpr.conclusion == 'success' }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ PATCHED_SPEC_ENTRY_POINT=spec/oas3.patched/openapi/public/${SPEC_ROOT_FILE}
PATCHED_SPEC_OUTPUT_DIR=spec/oas3.stitched/

SPEC_FETCHER=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} -v $(CURDIR):/workdir --entrypoint sh mikefarah/yq:4.30.8 script/download_spec.sh
SPEC_PATCHED_FILE=oas3.stitched.metal.yaml

SPEC_DIR_FETCHED_FILE=spec/oas3.fetched/
SPEC_DIR_PATCHED_FILE=spec/oas3.patched/
Expand All @@ -41,27 +40,20 @@ OPENAPI_CODEGEN_SHA=sha256:be8c2ef6be22f695410c2cc13d0ec7fdf2533fc88a7f17288ad75
OPENAPI_CODEGEN_IMAGE=openapitools/openapi-generator-cli@${OPENAPI_CODEGEN_SHA}
DOCKER_OPENAPI=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} -v $(CURDIR):/local ${OPENAPI_CODEGEN_IMAGE}

docker_run: clean pre-spec-patch-dir pull docker_generate_spec docker_generate move-workflow build_client
docker_run: clean patch pull docker_generate move-workflow build_client

pull:
${CRI} pull ${OPENAPI_CODEGEN_IMAGE}

docker_generate:
${DOCKER_OPENAPI} generate \
-i /local/${PATCHED_SPEC_OUTPUT_DIR}/${SPEC_PATCHED_FILE} \
-i /local/${PATCHED_SPEC_ENTRY_POINT} \
-g java \
-c /local/${OPENAPI_CONFIG} \
-o /local/${OPENAPI_GENERATED_CLIENT} \
--git-repo-id ${GIT_REPO} \
--git-user-id ${GIT_ORG}

docker_generate_spec:
${DOCKER_OPENAPI} generate \
-i /local/${PATCHED_SPEC_ENTRY_POINT} \
-g openapi-yaml \
-p skipOperationExample=true -p outputFile=oas3.stitched.metal.yaml \
-o /local/${PATCHED_SPEC_OUTPUT_DIR}

##
# Utility functions
##
Expand All @@ -70,10 +62,9 @@ fetch:

clean:
rm -rf ${OPENAPI_GENERATED_CLIENT}
rm -rf ${OPENAPI_GIT_DIR}

# executing patch apply shell script
pre-spec-patch-dir:
patch:
rm -rf ${SPEC_DIR_PATCHED_FILE}
cp -r ${SPEC_DIR_FETCHED_FILE} ${SPEC_DIR_PATCHED_FILE}

Expand Down
Loading

0 comments on commit 9a37829

Please # to comment.