-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π· poll for cybersource changes and create PR
- Loading branch information
1 parent
9e56bfc
commit 6904c36
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: 'Poll for Cybersource SDK release' | ||
|
||
on: | ||
schedule: | ||
# min hr day_month month day_week | ||
- cron: '0 16 * * *' | ||
|
||
permissions: | ||
contents: 'read' | ||
actions: '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=$( | ||
# echo hi | ||
# ) | ||
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" | ||
exit 0 | ||
fi | ||
fi | ||
echo "should_create_pr=false" >> "$GITHUB_OUTPUT" | ||
create_pr: | ||
runs-on: 'ubuntu-latest' | ||
needs: | ||
- 'check_version' | ||
if: ${{ needs.check_version.outputs.should_create_pr }} | ||
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: '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" |