Skip to content

Commit 17f3ac1

Browse files
authored
fix: compile versions rewrite (#273)
<!-- Thank you for proposing a pull request! Please note that SOME TESTS WILL LIKELY FAIL due to how GitHub exposes secrets in Pull Requests from forks. Someone from the team will review your Pull Request and respond. Please describe your change and any implementation details below. -->
1 parent b716a33 commit 17f3ac1

1 file changed

Lines changed: 18 additions & 65 deletions

File tree

.github/workflows/compile-versions.yml

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,14 @@ jobs:
1717
runs-on: 'ubuntu-latest'
1818

1919
steps:
20-
- uses: 'actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29' # ratchet:actions/checkout@v4
20+
- name: 'Checkout'
21+
uses: 'actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29' # ratchet:actions/checkout@v4
2122

22-
- uses: 'actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7' # ratchet:actions/setup-go@v5
23+
- name: 'Setup Go'
24+
uses: 'actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7' # ratchet:actions/setup-go@v5
2325
with:
2426
go-version-file: 'go.mod'
2527

26-
- name: 'Setup git'
27-
run: |-
28-
git config user.name "google-github-actions-bot"
29-
git config user.email "github-actions-bot@google.com"
30-
31-
# Fetch the existing PR branch, continue if not exists
32-
- name: 'Fetch remote'
33-
continue-on-error: true
34-
run: |-
35-
git fetch origin "${{ env.PR_BRANCH }}"
36-
37-
- name: 'Use PR_BRANCH'
38-
run: |-
39-
git switch -c "${{ env.PR_BRANCH }}"
40-
4128
- name: 'Get versions list'
4229
run: |-
4330
mkdir -p ./data
@@ -56,52 +43,18 @@ jobs:
5643
5744
echo "had_changes=true" >> ${GITHUB_OUTPUT}
5845
59-
git add ./data/versions.json
60-
git commit -m "Update gcloud versions ($(date --iso-8601=h))"
61-
git push -f origin "${{ env.PR_BRANCH }}"
62-
63-
- name: 'Create Pull Request'
64-
if: steps.updates.outputs.had_changes == 'true'
65-
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
46+
# Create a pull request with updated files
47+
- name: 'Create/Update Pull Request'
48+
if: |
49+
${{ steps.updates.outputs.had_changes == 'true' }}
50+
uses: 'abcxyz/pkg/.github/actions/create-pull-request@45258f93afbaca705ef0503c37ef88451ed45b02' # ratchet:abcxyz/pkg/.github/actions/create-pull-request@main
6651
with:
67-
github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
68-
script: |-
69-
const baseBranch = `${{ github.ref_name }}`;
70-
const prBranch = `${{ env.PR_BRANCH }}`;
71-
const prBody = `Update latest gcloud versions`;
72-
73-
try {
74-
const listResponse = await github.rest.pulls.list({
75-
owner: context.repo.owner,
76-
repo: context.repo.repo,
77-
state: `open`,
78-
head: `${context.repo.owner}:${prBranch}`,
79-
base: baseBranch,
80-
});
81-
82-
core.isDebug() && console.log(listResponse);
83-
84-
if(!listResponse.data.length) {
85-
const createResponse = await github.rest.pulls.create({
86-
owner: context.repo.owner,
87-
repo: context.repo.repo,
88-
title: `Update gcloud versions`,
89-
body: prBody,
90-
head: prBranch,
91-
base: baseBranch,
92-
});
93-
core.info(`Created PR #${createResponse.data.number} at ${createResponse.data.html_url}`);
94-
} else {
95-
const updateResponse = await github.rest.pulls.update({
96-
owner: context.repo.owner,
97-
repo: context.repo.repo,
98-
pull_number: listResponse.data[0].number,
99-
title: `Update gcloud versions`,
100-
body: prBody,
101-
});
102-
core.info(`Updated PR #${updateResponse.data.number} at ${updateResponse.data.html_url}`);
103-
}
104-
} catch(err) {
105-
console.error(err);
106-
core.setFailed(`Failed to create pull request: ${err}`);
107-
}
52+
token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
53+
base_branch: '${{ github.event.repository.default_branch }}'
54+
head_branch: '${{ env.PR_BRANCH }}'
55+
title: 'Update gcloud versions'
56+
body: 'Update latest gcloud versions'
57+
changed_paths: |-
58+
[
59+
"data/versions.json"
60+
]

0 commit comments

Comments
 (0)