Skip to content

Commit

Permalink
chore: re-onboard metalv1 to generate GHA workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Nov 17, 2023
1 parent 866421f commit b3e382f
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
83 changes: 83 additions & 0 deletions .github/workflows/sync-metalv1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Sync metalv1 spec

on:
workflow_dispatch:

jobs:
sync:
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- 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
id: fetch
run: |
make -f Makefile.metalv1 fetch
git add spec/services/metalv1
echo `git commit -m 'sync: fetch ${{ steps.date.outputs.date }} spec and apply patches'`
- name: Apply spec patches
id: patch
if: ${{ always() && steps.fetch.conclusion == 'success' }}
run: |
make -f Makefile.metalv1 patch
git add spec/services/metalv1
echo `git commit -m 'sync: patch spec with ${{ steps.date.outputs.date }} spec'`
- name: Generate code
id: generate
if: ${{ always() && steps.patch.conclusion == 'success' }}
run: |
make -f Makefile.metalv1 generate
git add services/metalv1
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@v5
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 for @${{ github.event.sender }}"
body: |
This API Sync PR was triggered by @${{ github.event.sender }} through [GitHub Actions workflow_displatch](https://github.com/equinix/equinix-sdk-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 }}"
31 changes: 31 additions & 0 deletions .github/workflows/test-metalv1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test metalv1 PR

on:
push:
paths:
- **/metalv1/**
pull_request:
paths:
- **/metalv1/**

jobs:
test:
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Verify Patches
run: make -f Makefile.metalv1 patch
- name: Generate
run: |
make -f Makefile.metalv1 generate
# Expect all changes to be accounted for
! git status --porcelain | grep .
Empty file added patches/services/metalv1/.keep
Empty file.
Empty file added spec/services/metalv1/.keep
Empty file.
2 changes: 1 addition & 1 deletion templates/.github/workflows/sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
sync__PACKAGE_NAME__:
sync:
strategy:
matrix:
go-version: [1.19.x]
Expand Down
Empty file.

0 comments on commit b3e382f

Please sign in to comment.