-
Notifications
You must be signed in to change notification settings - Fork 4
90 lines (78 loc) · 3.69 KB
/
zowe-versions_updateVersions_createPR.yml
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
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-v3-lts
required: true
type: choice
options:
- zowe-v1-lts
- zowe-v2-lts
- zowe-v3-lts
permissions:
contents: write
pull-requests: write
jobs:
update_versions_and_create_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Create Branch
run: |
version_name="${{ github.event.inputs.version }}"
branch_name="v$version_name/master"
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" --@zowe:registry=https://zowe.jfrog.io/zowe/api/npm/npm-local-release/)
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/; n; s/(rc: )[0-9]+/\11/ }" zowe-versions.yaml
- name: Commit and Push Changes
run: |
git config --global user.name ${{ secrets.ZOWE_ROBOT_USER }}
git config --global user.email ${{ secrets.ZOWE_ROBOT_EMAIL }}
git add zowe-versions.yaml
git commit -sm "Update component versions"
git push origin HEAD
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.ZOWE_ROBOT_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.ZOWE_ROBOT_TOKEN }}"\
https://api.github.com/repos/zowe/zowe-cli-standalone-package/pulls/$pr_number/requested_reviewers \
-d '{"team_reviewers":["zowe-cli-administrators"]}'
echo "Pull Request created successfully"