-
Notifications
You must be signed in to change notification settings - Fork 5
83 lines (80 loc) · 3.54 KB
/
sync-fabricv4.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Sync fabricv4 API 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@v5
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.fabricv4 fetch
git add spec/services/fabricv4
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.fabricv4 patch
git add spec/services/fabricv4
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.fabricv4 generate
git add services/fabricv4
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@v7
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.login }}"
body: |
This API Sync PR was triggered by @${{ github.event.sender.login }} 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 }}"