-
Notifications
You must be signed in to change notification settings - Fork 313
161 lines (155 loc) · 6.84 KB
/
generateAutoConfigs.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Generate Spring Auto-Configurations
on:
workflow_dispatch:
inputs:
branch_name:
description: PR branch name
required: true
default: "renovate/main-gcp-libraries-bom.version"
forked_repo:
description: Fork name (enter none if repo branch)
required: true
default: "renovate-bot/GoogleCloudPlatform-_-spring-cloud-gcp"
pull_request:
types: [opened]
jobs:
generateLibraries:
# Run this if workflow is manually triggered
# On initial opening of renovate or dependabot PR with matching branch condition,
# log information required for manually triggering workflow and exit with error to block PR
if: ${{ (github.event_name == 'workflow_dispatch') || startsWith(github.head_ref, 'renovate/main-gcp-libraries-bom.version') || startsWith(github.head_ref, 'dependabot/maven/com.google.cloud-libraries-bom') }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Get PR info
id: get_pr_info
continue-on-error: false
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "Please trigger update workflow manually. The following information may be helpful: "
echo "PR head repo full name: $HEAD_REPO_NAME"
echo "PR base repo full name: $BASE_REPO_NAME"
echo "PR branch name: $PR_BRANCH_NAME"
echo "Actor from PR event: $GITHUB_ACTOR"
exit 1
env:
HEAD_REPO_NAME: ${{ github.event.pull_request.head.repo.full_name }}
BASE_REPO_NAME: ${{ github.event.pull_request.base.repo.full_name }}
PR_BRANCH_NAME: ${{ github.head_ref }}
- name: Get libraries bom version
id: get_libraries_bom_version
continue-on-error: false
# Fetch updated pom file with the new libraries-bom version.
# This step differs slightly depending on whether the workflow is triggered for a forked repo.
run: |
set -x
sudo apt-get update
sudo apt-get install libxml2-utils
if [[ ${{ github.event.inputs.forked_repo }} != "none" ]]; then
git fetch https://github.com/${{ github.event.inputs.forked_repo }}.git ${{ github.event.inputs.branch_name }}
git checkout FETCH_HEAD -- spring-cloud-gcp-dependencies/pom.xml
else
git fetch origin ${{ github.event.inputs.branch_name }}
git checkout origin/${{ github.event.inputs.branch_name }} -- spring-cloud-gcp-dependencies/pom.xml
fi
echo "LIBRARIES_BOM_VERSION=$(xmllint --xpath "string(//*[local-name()='gcp-libraries-bom.version'])" spring-cloud-gcp-dependencies/pom.xml)" >> $GITHUB_OUTPUT
- name: Setup Java 17
uses: actions/setup-java@v1
with:
java-version: 17
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: bazelisk version
- uses: actions/setup-go@v3
- name: Install buildozer
run: |
go install github.com/bazelbuild/buildtools/buildozer@latest
export PATH=$PATH:$(go env GOPATH)/bin
buildozer --version
- name: Compile non-autogen libraries
continue-on-error: false
run: |
set -e
./mvnw \
--batch-mode \
--no-transfer-progress \
--show-version \
--threads 1.5C \
--define maven.test.skip=true \
--define maven.javadoc.skip=true \
install
- name: Generate libraries
continue-on-error: false
working-directory: spring-cloud-generator
run: |
set -x
set -e
export PATH=$PATH:$(go env GOPATH)/bin
buildozer --version
bash scripts/generate.sh
env:
LIBRARIES_BOM_VERSION: ${{ steps.get_libraries_bom_version.outputs.LIBRARIES_BOM_VERSION }}
- name: Sanity checks
continue-on-error: false
working-directory: spring-cloud-generator
run: |
set -x
bash scripts/sanity-checks.sh
- name: Check for generation errors
continue-on-error: false
working-directory: spring-cloud-generator
run: |
set -xe
if [[ ! -d failed-library-generations ]] || [[ $(ls *failed-library-generations | wc -l) -eq 0 ]]; then
echo 'no errors at generation'
exit 0
fi
for failed_lib_name in $(find failed-library-generations -printf '%f\n' | tail -n+2); do
echo "***** FAILED TO GENERATE LIBRARY: $failed_lib_name"
cat failed-library-generations/$failed_lib_name
done
exit 1
#Compares the current contents of spring-cloud-previews with the new generated libraries
- name: Detect changes
id: detect_changes
run: |
set -x
# Counts number of changed files
git add ./spring-cloud-previews
CHANGED_FILES=`git diff --cached --numstat | wc -l | awk '{print $1}'`
git reset -- ./spring-cloud-previews # unstage changes
echo "$CHANGED_FILES have changed after generation"
if [[ $CHANGED_FILES -eq 0 ]]; then
echo "Branch will not be updated"
fi
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_OUTPUT
- name: Push commit to branch
if: steps.detect_changes.outputs.CHANGED_FILES > 0
run: |
set -x
# stashes the changes from generated libs
git stash push -- spring-cloud-previews/
# configure author
git config --global user.name "Cloud Java Bot"
git config --global user.email "[email protected]"
# push changes to branch
if [[ ${{ github.event.inputs.forked_repo }} != "none" ]]; then
git fetch https://github.com/${{ github.event.inputs.forked_repo }}.git ${{ github.event.inputs.branch_name }}
git checkout FETCH_HEAD
git stash pop
git add ./spring-cloud-previews
git commit -m "chore: update starter modules in spring-cloud-previews"
git push https://github.com/${{ github.event.inputs.forked_repo }}.git HEAD:${{ github.event.inputs.branch_name }}
else
git fetch origin ${{ github.event.inputs.branch_name }}
git checkout ${{ github.event.inputs.branch_name }}
git reset --hard
git stash pop
git add ./spring-cloud-previews
git commit -m "chore: update starter modules in spring-cloud-previews"
git push -u origin ${{ github.event.inputs.branch_name }}
fi
env:
GITHUB_ACTOR_EMAIL: ${{ steps.determine_workflow_author_email.outputs.GITHUB_ACTOR_EMAIL }}
GITHUB_ACTOR_NAME: ${{ steps.determine_workflow_author_email.outputs.GITHUB_ACTOR_NAME }}
GITHUB_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}