Poll for Cybersource SDK release #162
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
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" |