Skip to content

Poll for Cybersource SDK release #109

Poll for Cybersource SDK release

Poll for Cybersource SDK release #109

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](https://github.com/CyberSource/cybersource-rest-client-node/releases/tag/$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: |-
body="$(cat << EOF
Upgrades to [Cybersource SDK v$latest_version](https://github.com/CyberSource/cybersource-rest-client-node/releases/tag/$latest_version).
Created via [Github Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
EOF
)"
gh pr create \
--base "${{ github.event.repository.default_branch }}" \
--head "$branch_name" \
--title "⬆️ Update Cybersource SDK to v$latest_version" \
--body "$body"