Skip to content

Update Versions and Create PR (zowe-versions) #5

Update Versions and Create PR (zowe-versions)

Update Versions and Create PR (zowe-versions) #5

name: Update Versions and Create PR (zowe-versions)
on:
workflow_dispatch:
inputs:
version:
description: 'Release Version (x.x.x)'
required: true
zowe_version:
description: "Zowe Version Tag"
default: zowe-v2-lts
required: true
type: choice
options:
- zowe-v1-lts
- zowe-v2-lts
jobs:
update_versions_and_create_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Create Branch
run: |
version_name="${{ github.event.inputs.version }}"
branch_name="update-versions-${version_name}"
git checkout -b "$branch_name"
- name: Get and Change Component Versions
id: get_versions
run: |
zowe_version="${{ github.event.inputs.zowe_version }}"
components=$(yq -r ".packages | with_entries(select(.value.\"$zowe_version\")) | keys | .[]" zowe-versions.yaml)
version="${{ github.event.inputs.version }}"
# echoing to txt file to later add this file as the PR description
echo "This PR updates the following package versions in zowe-versions.yaml for \`$zowe_version\`" >> description.txt
echo "| Updated Package | Old Version | New Version |" >> description.txt
echo "| --- | --- | --- |" >> description.txt
for component in $components; do
current_version=$(grep -A 2 "^ $component:" zowe-versions.yaml | grep "$zowe_version" | awk '{print $2}' | tr -d '\r')
new_version=$(npm view @zowe/$component "dist-tags.$zowe_version")
if [[ "$new_version" != "$current_version" ]]; then
echo "|$component | $current_version | $new_version|" >> description.txt
# Replaces the version number. If it doesn't match on the first line after the component, it goes to the next line and checks again.
sed -i -E "/^ $component:/ { n; s/($zowe_version: ).*/\1$new_version/; t; n; s/($zowe_version: ).*/\1$new_version/ }" zowe-versions.yaml
fi
done
# Update zowe-versions.yaml tags section (always sets rc = 1)
sed -i -E "/$zowe_version:/ { n; s/(version: ).*/\1$version/; s/(rc: )[0-9]+/\11/ }" zowe-versions.yaml
- name: Commit and Push Changes
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add zowe-versions.yaml
git commit -sm "Update component versions"
git push origin HEAD
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version_name="${{ github.event.inputs.version }}"
branch_name="v$version_name/master"
pr_title="Update zowe component versions for $version_name"
body_file=description.txt
pr_url=$(gh pr create --base master --head "$branch_name" --title "$pr_title" --body-file "$body_file")
pr_number=$(echo "$pr_url" | sed 's/.*\/\([0-9]\+\)$/\1/')
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
https://api.github.com/repos/zowe/zowe-cli-standalone-package/pulls/$pr_number/requested_reviewers \
-d '{"team_reviewers":["@zowe/zowe-cli-administrators"]}'
echo "Pull Request created successfully"