-
Notifications
You must be signed in to change notification settings - Fork 6
142 lines (122 loc) · 5.27 KB
/
generate.yml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Generate Library & Open Pull Request
# Uses protos from HEAD of https://github.com/googleapis/google-cloudevents
# and tooling from HEAD of this repository to update all generated code.
#
# Creates a PR whose branch will include an unmodified snapshot of the
# tooling used to generate changes.
on:
schedule:
# Run at the end of every day. (10:10pm PT, 5:10am UTC)
- cron: 10 5 * * *
workflow_dispatch:
jobs:
# Create a pull request.
create-pr:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
# Library & Data Source repos using side-by-side checkout.
LIBRARY_CHECKOUT_PATH: library # sync with defaults.run.working-directory
DATA_SOURCE_CHECKOUT_PATH: protos-source-repo
steps:
- name: Go Library > Checkout Repository
uses: actions/checkout@v4
with:
path: ${{ env.LIBRARY_CHECKOUT_PATH }}
- name: Proto Schemas > Checkout Repository
uses: actions/checkout@v4
with:
repository: googleapis/google-cloudevents
path: ${{ env.DATA_SOURCE_CHECKOUT_PATH }}
- name: Set Environment
# Validation Test execution requires absolute path to testdata.
run: echo "GENERATE_DATA_SOURCE=${PWD}/${DATA_SOURCE_CHECKOUT_PATH}" | tee -a $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.19.x
- name: Install the generator
run: bash tools/setup-generator.sh
working-directory: ${{ env.LIBRARY_CHECKOUT_PATH }}
- name: Run the generator
run: bash ./generate-code.sh
working-directory: ${{ env.LIBRARY_CHECKOUT_PATH }}
env:
GENERATE_PROTOC_PATH: tmp/protobuf/bin/protoc
GOFLAGS: "-v"
- name: View generator output
if: ${{ failure() }}
working-directory: ${{ env.LIBRARY_CHECKOUT_PATH }}
run: |
git add -N . # Needed if files are untracked
git diff
# This step identifies the github revision of the data source repository.
# This is used to create a detailed Pull Request description.
- name: Source Version
id: source-version
if: ${{ always() }}
run: |
rev=$(git rev-parse --short HEAD)
echo "revision=${rev}" | tee -a $GITHUB_OUTPUT
working-directory: ${{ env.DATA_SOURCE_CHECKOUT_PATH }}
- name: Create a pull request with updates
# https://github.com/googleapis/code-suggester#Action
uses: googleapis/code-suggester@v4
env:
# Provided by the GitHub Automation team
ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
with:
command: pr
upstream_owner: ${{ github.repository_owner }}
upstream_repo: 'google-cloudevents-go'
# Pull Request Title
title: 'feat: Run the code generator'
# Commit Message
message: 'feat: Run the code generator (${{ steps.source-version.outputs.revision }})'
description: |
:robot: Auto-generated Pull Request.
This PR was created from a recent update in the [google-cloudevents](https://github.com/googleapis/google-cloudevents) repository.
Specifically, the change at https://github.com/googleapis/google-cloudevents/commit/${{ steps.source-version.outputs.revision }}.
Future updates to the protos in that repository made before this PR is
merged will lead to a force push update of this Pull Request with
the latest changes.
* **Generator configuration:** https://github.com/${{ github.repository }}/blob/${{ steps.source-version.outputs.revision }}/.github/workflows/generate.yml
* **Generator Setup Script:** https://github.com/${{ github.repository }}/blob/${{ github.sha }}/tools/setup-generator.sh
* **Generator script:** https://github.com/${{ github.repository }}/blob/${{ github.sha }}/generate-code.sh
# A static branch name and force pushes are meant to create
# a single open PR with all pending updates.
branch: 'generator'
force: true
fork: true # action automatically forks repo
git_dir: ${{ env.LIBRARY_CHECKOUT_PATH }}
primary: 'main'
- name: Notify for failure
if: ${{ failure() && github.event_name == 'schedule' }}
uses: actions/github-script@v7
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Library generation failed (${{ steps.source-version.outputs.revision }})',
body: `See [failed job](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`,
});