-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (110 loc) · 4.18 KB
/
cybersource-release-poll.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
name: 'Poll for Cybersource SDK release'
on:
schedule:
# min hr day_month month day_week
- cron: '0 16 * * *'
push:
paths:
- '.github/workflows/cybersource-release-poll.yaml'
permissions:
contents: 'write'
actions: 'write'
pull-requests: 'write'
jobs:
check_version:
runs-on: 'ubuntu-latest'
outputs:
should_create_pr: '${{ steps.check.outputs.should_create_pr }}'
latest_version: '${{ steps.check.outputs.latest_version }}'
branch_name: '${{ steps.check.outputs.branch_name }}'
steps:
- name: 'Checkout Repository 🛎️'
uses: 'actions/checkout@v4'
- name: 'Check for Cybersource SDK release 🔖'
id: 'check'
working-directory: 'scripts'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
run: |-
source "$(pwd)/lib/variables.sh"
source "$(pwd)/lib/check-latest-release.sh"
update_text="$(
check_latest_release \
"CyberSource/cybersource-rest-client-node" \
"$cybersource_rest_client_version" \
2>&1
)"
# if the update message exists
if [ -n "$update_text" ]; then
latest_version=$(echo "$update_text" | sed -E 's/^.+ → ([0-9.a-z -]+).*$/\1/')
branch_name="chore/upgrade-cybersource-sdk-v$latest_version"
# if the branch does not exist yet
if [ -z "$(git ls-remote --heads origin "refs/heads/$branch_name")" ]; then
echo "Cybersource SDK version $latest_version update available."
echo "should_create_pr=true" >> "$GITHUB_OUTPUT"
echo "latest_version=$latest_version" >> "$GITHUB_OUTPUT"
echo "branch_name=$branch_name" >> "$GITHUB_OUTPUT"
echo "Upgrade to Cybersource SDK v$latest_version available." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
fi
echo "should_create_pr=false" >> "$GITHUB_OUTPUT"
echo "No upgrades available." >> "$GITHUB_STEP_SUMMARY"
create_pr:
runs-on: 'ubuntu-latest'
needs:
- 'check_version'
if: ${{ needs.check_version.outputs.should_create_pr == 'true' }}
env:
latest_version: '${{ needs.check_version.outputs.latest_version }}'
branch_name: '${{ needs.check_version.outputs.branch_name }}'
steps:
- name: 'Checkout Repository 🛎️'
uses: 'actions/checkout@v4'
- name: 'Setup Nix ❄️'
uses: 'cachix/install-nix-action@v27'
with:
nix_path: 'nixpkgs=channel:nixos-unstable'
github_access_token: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Create branch for PR 🔀'
run: |-
git switch -C "$branch_name"
- name: 'Update variables 🔧'
run: |-
vars_file=scripts/lib/variables.sh
# update the version file to
sed -i -E \
's/^(cybersource_rest_client_version=").+?(")$/\1'"$latest_version"'\2/gm' \
"$vars_file"
- name: 'Update Cybersource ⬆️'
timeout-minutes: 5
run: |-
nix develop --impure --command "scripts/develop.sh"
- name: 'Set git user 👤'
run: |-
git config --global user.name 'Cybersource Upgrade Bot'
git config --global user.email 'lorleans@paciolan.com'
- name: 'Stage changes 📎'
run: |-
git add \
scripts/lib/variables.sh \
modules/cybersource-rest-client-node \
src/ \
;
git status
# TODO: should we check if there are other unstaged changes (and consider that an error)
- name: 'Commit changes 📝'
run: |-
git commit -m "⬆️ update cybersource SDK to v$latest_version"
- name: 'Push changes 📤'
run: |-
git push -u origin "$branch_name"
- name: 'Create PR 📬'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
run: |-
gh pr create \
--base "${{ github.event.repository.default_branch }}" \
--head "$branch_name" \
--title "⬆️ Update Cybersource SDK to v$latest_version" \
--body "Created by Github action"