Sync #18
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: Sync | |
on: | |
workflow_dispatch: | |
env: | |
PYTHON_VERSION: 3.8 | |
jobs: | |
sync: | |
name: Regenerate SDK with latest API spec | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade PyYAML | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT" | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: GitHub user | |
run: | | |
# https://api.github.com/users/github-actions[bot] | |
git config user.name 'github-actions[bot]' | |
git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
- name: Fetch latest spec to oas.fetched/ | |
id: fetch | |
run: | | |
make fetch | |
git add oas3.fetched | |
echo `git commit -m 'sync: fetch ${{ steps.date.outputs.date }} spec and apply patches'` | |
- name: Build single-file spec in oas3.stitched/metal_openapi.yaml | |
id: stitch | |
if: ${{ always() && steps.fetch.conclusion == 'success' }} | |
run: | | |
make stitch-spec | |
git add oas3.stitched | |
echo `git commit -m 'sync: stitch spec with ${{ steps.date.outputs.date }} spec'` | |
- name: Patch spec and build ./metal_openapi.fixed.yaml | |
id: patch | |
if: ${{ always() && steps.stitch.conclusion == 'success' }} | |
run: | | |
make patch-spec -o stitch-spec | |
git add metal_openapi.fixed.yaml | |
echo `git commit -m 'sync: patch spec with ${{ steps.date.outputs.date }} spec'` | |
- name: Generate SDK to ./equinix_metal | |
id: generate | |
if: ${{ always() && steps.patch.conclusion == 'success' }} | |
run: | | |
make generate -o patch-spec -o clean | |
git add equinix_metal | |
echo `git commit -m 'sync: generate client with ${{ steps.date.outputs.date }} spec'` | |
- name: Create Pull Request | |
id: cpr | |
uses: peter-evans/create-pull-request@v6 | |
if: ${{ always() && steps.fetch.conclusion == 'success' }} | |
with: | |
branch: sync/gh | |
branch-suffix: timestamp | |
author: github-actions[bot] <41898282+github-actions[bot]@users.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-python/actions?query=event%3Aworkflow_dispatch) | |
on ${{ steps.date.outputs.date }}. | |
* latest Equinix Metal API spec have been fetched | |
* patches have been applied | |
* generated client has been updated | |
delete-branch: true | |
draft: ${{ steps.patch.conclusion == 'failure' || steps.stitch.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 stitch | |
uses: mshick/add-pr-comment@v2 | |
if: ${{ always() && steps.stitch.conclusion == 'failure' && steps.cpr.conclusion == 'success' }} | |
with: | |
issue: ${{ steps.cpr.outputs.pull-request-number }} | |
message: Failed to rebuild single-file 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 }}" |