-
Notifications
You must be signed in to change notification settings - Fork 8
147 lines (128 loc) Β· 5.58 KB
/
codegen_diff.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
143
144
145
146
# name: Generate codegen diff
# on:
# pull_request:
# paths:
# - "codegenerator/**"
# - "scenarios/test_codegen/**"
# defaults:
# run:
# working-directory: scenarios/test_codegen
# env:
# CARGO_TERM_COLOR: always
# jobs:
# get_codegen_diff:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Setup rust cache
# uses: actions/cache@v3
# with:
# path: |
# ~/.cargo/git
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# # using both of these paths to hedge bets on which is correct.
# ./codegenerator/target
# ./target
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# restore-keys: |
# ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
# ${{ runner.os }}-cargo-
# - uses: pnpm/action-setup@v3
# with:
# version: 8.9
# - name: Get pnpm store directory (if this seems stable and static we can hard-code it again) # Source: https://github.com/pnpm/action-setup#use-cache-to-reduce-installation-time
# id: pnpm-cache
# shell: bash
# run: |
# echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# - uses: actions/cache@v3
# name: Setup pnpm cache
# with:
# path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
# key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# restore-keys: |
# ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# ${{ runner.os }}-pnpm-store-
# - name: Get commit hash
# id: gethash
# run: echo "::set-output name=hash::$(git rev-parse --short "$GITHUB_SHA")"
# - name: Run envio codegen
# run: pnpm codegen
# - name: Setup Git
# run: |
# git config --global user.name "Codegen Bot Beep Boop"
# git config --global user.email "[email protected]"
# - name: Authenticate with GitHub
# env:
# GH_PAT: ${{ secrets.GH_PAT }}
# run: |
# echo "https://${GH_PAT}:[email protected]" > ~/.git-credentials
# git config --global credential.helper store
# - name: Get the branch name
# id: extract_branch
# run: |
# # ${{ github.head_ref || github.ref_name }} or ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} both work. `github.head_ref` doesn't work for direct pushes (not PRs).
# # Reference: https://stackoverflow.com/questions/60300169/how-to-get-branch-name-on-github-action
# echo "::set-output name=branch::$(echo ${{ github.head_ref || github.ref_name }})"
# - name: Commit and push changes to output repository
# id: git_push
# run: |
# git clone https://github.com/enviodev/test-codegen-output.git
# cd test-codegen-output
# git fetch origin
# if git branch -r | grep -q "origin/${{ steps.extract_branch.outputs.branch }}"; then
# git checkout ${{ steps.extract_branch.outputs.branch }}
# git pull origin ${{ steps.extract_branch.outputs.branch }}
# else
# git checkout -b ${{ steps.extract_branch.outputs.branch }}
# fi
# find . -not -name ".git" -not -name ".gitignore" -mindepth 1 -maxdepth 1 -exec rm -rf {} \;
# cp -r ../generated/* .
# git add -A
# if git diff --staged --quiet; then
# echo "No changes to commit"
# echo "::set-output name=no_changes::true"
# exit 0
# else
# git commit -m "Update based on commit ${{ steps.gethash.outputs.hash }} in parent repo"
# git push origin ${{ steps.extract_branch.outputs.branch }}
# echo "::set-output name=no_changes::false"
# fi
# - name: Get diff URL
# id: diff
# run: |
# cd test-codegen-output
# echo "::set-output name=url::https://github.com/enviodev/test-codegen-output/compare/$(git rev-parse main)...${{ steps.extract_branch.outputs.branch }}"
# - name: Comment PR
# uses: actions/github-script@v6
# with:
# script: |
# const issue_number = context.issue.number;
# const existing_comments = await github.rest.issues.listComments({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: issue_number
# });
# const message = `Here's the [diff](${{ steps.diff.outputs.url }}) of the codegen output.ππ§ π¦`;
# // This goes through existing comments to make sure the comment is only made once.
# const existing_comment = existing_comments.data.find(comment => comment.body.includes(message));
# if (!existing_comment) {
# if (${{ steps.git_push.outputs.no_changes }} == "true") {
# github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: issue_number,
# body: "No changes detected to the codegen output. π¦"
# });
# } else {
# github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: issue_number,
# body: message
# });
# }
# }