Skip to content

Commit 756f093

Browse files
Add tools for releasing the Devfile schema (#285)
* Add tools for releasing the Devfile schema - Adds a script to run that upda - Adds a GitHub workflow action that publishes the released schemas to the Devfile website Signed-off-by: John Collier <jcollier@redhat.com> * Cleanup Signed-off-by: John Collier <jcollier@redhat.com> * Update make-release.sh Co-authored-by: Angel Misevski <amisevsk@redhat.com> * Update .github/workflows/release-schema.yaml Co-authored-by: Angel Misevski <amisevsk@redhat.com> * Update .github/workflows/release-schema.yaml Co-authored-by: Angel Misevski <amisevsk@redhat.com> * Address review comments - Remove force push when pushing to PR branch - Add check for proper schema version format - Add fix for schema versions where the patch version is >=10 Signed-off-by: John Collier <jcollier@redhat.com> * Update script to bump schema version on master Signed-off-by: John Collier <jcollier@redhat.com> * Address review comments - Don't publish to stable if stable has a never version than what's being published - Don't update master schema version if the master version is newer than what's being published - Update design doc to clearly state that a Github token is required to run the script - Clean up the release script for some clarity Signed-off-by: John Collier <jcollier@redhat.com> * Fix check for old schema version Signed-off-by: John Collier <jcollier@redhat.com> * Update warn message Signed-off-by: John Collier <jcollier@redhat.com> Co-authored-by: Angel Misevski <amisevsk@redhat.com>
1 parent f33d298 commit 756f093

File tree

3 files changed

+256
-5
lines changed

3 files changed

+256
-5
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Release Devfile Schema
2+
3+
# Triggers the workflow when a release is published on GitHub.
4+
on:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
release-json-schema:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout devfile docs
13+
uses: actions/checkout@v2
14+
with:
15+
repository: devfile/docs
16+
persist-credentials: false
17+
path: docs-repo
18+
- name: Checkout devfile api
19+
uses: actions/checkout@v2
20+
with:
21+
path: api-repo
22+
- name: Get the version being released
23+
id: get_version
24+
run: echo ::set-output name=version::$(cat api-repo/schemas/latest/jsonSchemaVersion.txt)
25+
- name: Overwrite Stable Json Schema in Docs if needed
26+
run: |
27+
if [ ! -f docs-repo/docs/modules/user-guide/attachments/jsonschemas/stable/jsonSchemaVersion.txt ]; then
28+
# Stable version doesn't currently exist, so just copy over the schema we're releasing
29+
mkdir -p docs-repo/docs/modules/user-guide/attachments/jsonschemas/stable
30+
cp -f api-repo/schemas/latest/{devfile.json,jsonSchemaVersion.txt} \
31+
docs-repo/docs/modules/user-guide/attachments/jsonschemas/stable/
32+
exit 0
33+
fi
34+
35+
# Parse the schema version that's being released
36+
IFS='.' read -a semver <<< "${{ steps.get_version.outputs.VERSION }}"
37+
MAJOR=${semver[0]}
38+
MINOR=${semver[1]}
39+
BUGFIX=${semver[2]}
40+
41+
# Parse the version currently set to stable
42+
stableVersion=`cat docs-repo/docs/modules/user-guide/attachments/jsonschemas/stable/jsonSchemaVersion.txt`
43+
IFS='.' read -a stableSemVer <<< "$stableVersion"
44+
stableMajor=${stableSemVer[0]}
45+
stableMinor=${stableSemVer[1]}
46+
stableBugfix=$(echo ${stableSemVer[2]} | awk -F '-' '{print $1}')
47+
48+
# Compare the two versions, only update stable if needed
49+
if ((stableMajor <= MAJOR)) && ((stableMinor <= MINOR)) && ((stableBugfix <= BUGFIX)); then
50+
cp -f api-repo/schemas/latest/{devfile.json,jsonSchemaVersion.txt} \
51+
docs-repo/docs/modules/user-guide/attachments/jsonschemas/stable/
52+
else
53+
echo "::warning::Current stable schema version is newer than the schema version being released, so the stable schema will not be updated."
54+
fi
55+
- name: Copy released Json Schema to Docs
56+
run: |
57+
mkdir -p docs-repo/docs/modules/user-guide/attachments/jsonschemas/${{ steps.get_version.outputs.VERSION }} && \
58+
cp -f api-repo/schemas/latest/devfile.json \
59+
docs-repo/docs/modules/user-guide/attachments/jsonschemas/${{ steps.get_version.outputs.VERSION }}/devfile.json
60+
- name: Push to the devfile/docs repo
61+
working-directory: docs-repo/
62+
run: |
63+
if [ "$(git status -s)" == "" ]
64+
then
65+
echo "Nothing to commit, Json schema didn't change"
66+
exit 0
67+
fi
68+
69+
lastCommit="$(cd ../api-repo; git log -1 --format=%H)"
70+
lastCommitterName="$(cd ../api-repo; git log -1 --format=%an)"
71+
lastCommitterEmail="$(cd ../api-repo; git log -1 --format=%ae)"
72+
73+
git config --global user.email "${lastCommitterEmail}"
74+
git config --global user.name "${lastCommitterName}"
75+
76+
git add --all
77+
git commit -m "Update devfile schema based on devfile/api@${lastCommit}"
78+
git push "https://devfile-ci-robot:${{secrets.DOCS_UPDATE_SECRET}}@github.com/devfile/docs"
79+

docs/proposals/versioning-and-release.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ The following steps outline the steps done to release a new version of the Devfi
5858

5959
1) The release engineer tasked with creating the release clones the repository (and checks out the release branch if one already exists)
6060

61-
2) `make-release.sh <schema-version> <k8s-api-version>` is run:
61+
2) The release engineer installs the `hub` CLI from https://github.com/github/hub if it is not already installed on their machine.
62+
63+
3) `export GITHUB_TOKEN=<token>` is run, where `<token>` is a GitHub personal access token with `repo` permissions created from https://github.com/settings/tokens.
64+
65+
4) `./make-release.sh <schema-version> <k8s-api-version>` is run:
6266

6367
i) A release branch (the name corresponding to the schema version) is created, if one does not already exist.
6468

@@ -68,14 +72,16 @@ The following steps outline the steps done to release a new version of the Devfi
6872

6973
iv) A new commit including the changes
7074

71-
v) Finally, a PR is opened to merge these changes into the release branch
75+
v) A PR is opened to merge these changes into the release branch
76+
77+
vi) The schema version on the master branch is bumped and a PR is opened, provided the schema version passed in is **not** older than the master branch schema version.
7278

73-
3) Once the release PR is approved and merged, the release engineer creates a new release on GitHub based off the release branch that was just created and includes the generated `devfile.json` as a release artifact.
79+
5) Once the release PR is approved and merged, the release engineer creates a new release on GitHub based off the release branch that was just created and includes the generated `devfile.json` as a release artifact.
7480
- The tag `v{major}.{minor}.{bugfix}`, where the `{major}.{minor}.{bugfix}` corresponds to the devfile schema version, is used to enable the new version of the API to be pulled in as a Go module.
7581

76-
4) Once the release is published, GitHub actions run to publish the new schema to devfile.io. The “stable” schema is also updated to point to the new schema.
82+
6) Once the release is published, GitHub actions run to publish the new schema to devfile.io. The “stable” schema is also updated to point to the new schema.
7783

78-
5) Make a release announcement on the devfile mailing list and slack channel
84+
7) Make a release announcement on the devfile mailing list and slack channel
7985

8086
An example pull request, `make-release.sh` script and GitHub action can be found here:
8187
- [Release Pull Request](https://github.com/johnmcollier/api/pull/7)

make-release.sh

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2020 Red Hat, Inc.
4+
# This program and the accompanying materials are made
5+
# available under the terms of the Eclipse Public License 2.0
6+
# which is available at https://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
# Contributors:
11+
# Red Hat, Inc. - initial API and implementation
12+
13+
# Based on https://github.com/che-incubator/chectl/blob/master/make-release.sh
14+
15+
set -e
16+
set -u
17+
18+
usage ()
19+
{ echo "Usage: ./make-release.sh <schema-version> <k8s-api-version>"
20+
exit
21+
}
22+
23+
if [[ $# -lt 2 ]]; then usage; fi
24+
25+
SCHEMA_VERSION=$1
26+
K8S_VERSION=$2
27+
28+
if ! command -v hub > /dev/null; then
29+
echo "[ERROR] The hub CLI needs to be installed. See https://github.com/github/hub/releases"
30+
exit
31+
fi
32+
if [[ -z "${GITHUB_TOKEN}" ]]; then
33+
echo "[ERROR] The GITHUB_TOKEN environment variable must be set."
34+
exit
35+
fi
36+
37+
if ! [[ "$SCHEMA_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
38+
echo >&2 "$SCHEMA_VERSION isn't a valid semver tag for the schema. Aborting..."
39+
exit 1
40+
fi
41+
42+
43+
init() {
44+
BRANCH="${SCHEMA_VERSION%.*}.x"
45+
}
46+
47+
apply_sed() {
48+
SHORT_UNAME=$(uname -s)
49+
if [ "$(uname)" == "Darwin" ]; then
50+
sed -i '' "$1" "$2"
51+
elif [ "${SHORT_UNAME:0:5}" == "Linux" ]; then
52+
sed -i "$1" "$2"
53+
fi
54+
}
55+
56+
resetChanges() {
57+
echo "[INFO] Reset changes in $1 branch"
58+
git reset --hard
59+
git checkout $1
60+
git fetch origin --prune
61+
git pull origin $1
62+
}
63+
64+
checkoutToReleaseBranch() {
65+
echo "[INFO] Checking out to $BRANCH branch."
66+
if git ls-remote -q --heads | grep -q $BRANCH ; then
67+
echo "[INFO] $BRANCH exists."
68+
resetChanges $BRANCH
69+
else
70+
echo "[INFO] $BRANCH does not exist. Will create a new one from master."
71+
resetChanges master
72+
git push origin master:$BRANCH
73+
fi
74+
git checkout -B $SCHEMA_VERSION
75+
}
76+
77+
setVersionAndBuild() {
78+
# Replace pre-release version with release version
79+
apply_sed "s#jsonschema:version=.*#jsonschema:version=${SCHEMA_VERSION}#g" pkg/apis/workspaces/$K8S_VERSION/doc.go #src/constants.ts
80+
81+
# Generate the schema
82+
./build.sh
83+
}
84+
85+
commitChanges() {
86+
echo "[INFO] Pushing changes to $SCHEMA_VERSION branch"
87+
git add -A
88+
git commit -s -m "$1"
89+
git push origin $SCHEMA_VERSION
90+
}
91+
92+
createReleaseBranch() {
93+
echo "[INFO] Create the release branch based on $SCHEMA_VERSION"
94+
git push origin $SCHEMA_VERSION
95+
}
96+
97+
createPR() {
98+
echo "[INFO] Creating a PR"
99+
hub pull-request --base ${BRANCH} --head ${SCHEMA_VERSION} -m "$1"
100+
}
101+
102+
bumpVersion() {
103+
IFS='.' read -a semver <<< "$SCHEMA_VERSION"
104+
MAJOR=${semver[0]}
105+
MINOR=${semver[1]}
106+
SCHEMA_VERSION=$MAJOR.$((MINOR+1)).0-alpha
107+
}
108+
109+
updateVersionOnMaster() {
110+
# Checkout to a PR branch based on master to make our changes in
111+
git checkout -b $SCHEMA_VERSION
112+
113+
# Set the schema version to the new version (with -alpha appended) and build the schemas
114+
setVersionAndBuild
115+
116+
commitChanges "chore(post-release): bump schema version to ${SCHEMA_VERSION}"
117+
}
118+
119+
compareMasterVersion() {
120+
# Parse the version passed in.
121+
IFS='.' read -a semver <<< "$SCHEMA_VERSION"
122+
MAJOR=${semver[0]}
123+
MINOR=${semver[1]}
124+
BUGFIX=${semver[2]}
125+
126+
# Parse the version currently set in the schema
127+
latestVersion=`cat schemas/latest/jsonSchemaVersion.txt`
128+
IFS='.' read -a latestSemVer <<< "$latestVersion"
129+
local latestMajor=${latestSemVer[0]}
130+
local latestMinor=${latestSemVer[1]}
131+
local latestBugfix=$(echo ${latestSemVer[2]} | awk -F '-' '{print $1}')
132+
133+
# Compare the new vers
134+
if ((latestMajor <= MAJOR)) && ((latestMinor <= MINOR)) && ((latestBugfix <= BUGFIX)); then
135+
return 0
136+
else
137+
return 1
138+
fi
139+
}
140+
141+
run() {
142+
# Create the release branch and open a PR against the release branch, updating the release version
143+
echo "[INFO] Releasing a new ${SCHEMA_VERSION} version"
144+
checkoutToReleaseBranch
145+
setVersionAndBuild
146+
commitChanges "chore(release): release version ${SCHEMA_VERSION}"
147+
createReleaseBranch
148+
createPR "Release version ${SCHEMA_VERSION}"
149+
150+
# If needed, bump the schema version in master and open a PR against master
151+
# Switch back to the master branch
152+
BRANCH=master
153+
resetChanges $BRANCH
154+
if compareMasterVersion; then
155+
echo "[INFO] Updating schema version on master to ${SCHEMA_VERSION}"
156+
bumpVersion
157+
updateVersionOnMaster
158+
createPR "Bump schema version on master to ${SCHEMA_VERSION}"
159+
else
160+
echo "[WARN] The passed in schema version ${SCHEMA_VERSION} is less than the current version on master, so not updating the master branch version"
161+
exit
162+
fi
163+
}
164+
165+
init
166+
run

0 commit comments

Comments
 (0)