Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release changelog generator #84

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ main
# File created running tests
tests/**/tmp/

# Mac related files
.DS_Store

# Release utility changelog files
CHANGELOG.md
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g

## Updating Library Schema

Run `updateApi.sh` can update to use latest `github.com/devfile/api` and update the schema saved under `pkg/devfile/parser/data`
Executing `./scripts/updateApi.sh` fetches the latest `github.com/devfile/api` go mod and updates the schema saved under `pkg/devfile/parser/data`

The script also accepts version number as an argument to update devfile schema for a specific devfile version.
For example, run the following command will update devfile schema for 2.0.0
The script also accepts a version number as an argument to update the devfile schema for a specific devfile version.
For example, running the following command will update the devfile schema for 2.0.0
```
./updateApi.sh 2.0.0
```
Running the script with no arguments will default to update the latest devfile version
Running the script with no arguments will default to update the latest devfile version.

## Projects using devfile/library

Expand All @@ -90,3 +90,5 @@ Issues are tracked in the [devfile/api](https://github.com/devfile/api) repo wit
## Releases

For devfile/library releases, please check the release [page](https://github.com/devfile/library/releases).

Note: To generate a changelog for a new release, execute `./scripts/changelog-script.sh v1.x.y` for all the changes since the release v1.x.y
57 changes: 57 additions & 0 deletions scripts/changelog-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

#!/bin/bash

# This script uses github_changelog_generator to generate a changelog and requires:
#
# 1. set an env GITHUB_TOKEN for the Github token
# 2. previous release as an arg, to generate changelog since the mentioned release
# 3. github_changelog_generator be installed where the script is being executed
#
# A CHANGELOG.md is generated and it's contents can be copy-pasted on the Github release

#TODO: Since issue tracking happens in devfile/api, github_changelog_generator cannot
# detect the issues from a different repository. Need to check if this is achievable.

BLUE='\033[1;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
BOLD='\033[1m'

# Ensure the github token is set
if [ -z "$GITHUB_TOKEN" ]
then
echo -e "${RED}GITHUB_TOKEN env variable is empty..\nGet your GitHub token from https://github.com/settings/tokens and export GITHUB_TOKEN=<token>${NC}"
exit 1
fi

# Ensure there is a release version passed in
if [ -z "$1" ]
then
echo -e "${RED}The last release version needs to be provided. Changelog will be generated since that release..${NC}"
echo -e "${RED}Example: ./changelog-script.sh v1.0.0-alpha.2 will generate a changelog for all the changes since release v1.0.0-alpha.2${NC}"
exit 1
fi

# Ensure github_changelog_generator is installed
if ! command -v github_changelog_generator &> /dev/null
then
echo -e "${RED}The command github_changelog_generator could not be found, please install the command to generate a changelog${NC}"
exit 1
fi


github_changelog_generator \
-u devfile \
-p library \
-t $GITHUB_TOKEN \
--since-tag $1 \

RESULT=$?

if [ $RESULT -eq 0 ]; then
echo -e "${GREEN}Changelog since release $1 generated at $PWD/CHANGELOG.md${NC}"
else
echo -e "${RED}Unable to generate changelog using github_changelog_generator${NC}"
exit 1
fi
7 changes: 4 additions & 3 deletions updateApi.sh → scripts/updateApi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BOLD='\033[1m'

set -e

DIR=$(dirname $0)
CURRENT_DIR=$(pwd)
API_PKG="github.com/devfile/api/v2"
SCHEMA_URL_MASTER="https://raw.githubusercontent.com/devfile/api/main/schemas/latest/devfile.json"
Expand All @@ -16,12 +17,12 @@ SCHEMA_URL_MASTER="https://raw.githubusercontent.com/devfile/api/main/schemas/la
SCHEMA_URL_200="https://raw.githubusercontent.com/devfile/api/2.0.x/schemas/latest/devfile.json"
PACKAGE_VERSION_200="version200"
JSON_SCHEMA_200="JsonSchema200"
FILE_PATH_200="./pkg/devfile/parser/data/v2/2.0.0/devfileJsonSchema200.go"
FILE_PATH_200="$DIR/../pkg/devfile/parser/data/v2/2.0.0/devfileJsonSchema200.go"

# 2.1.0 devfile
PACKAGE_VERSION_210="version210"
JSON_SCHEMA_210="JsonSchema210"
FILE_PATH_210="./pkg/devfile/parser/data/v2/2.1.0/devfileJsonSchema210.go"
FILE_PATH_210="$DIR/../pkg/devfile/parser/data/v2/2.1.0/devfileJsonSchema210.go"


onError() {
Expand Down Expand Up @@ -55,5 +56,5 @@ schema=$(curl -L "${SCHEMA_URL}")

#replace all ` with ' and write to schema file
echo -e "${GREEN}Write to go file${NC}"
go build *.go
go build $DIR/../*.go
./main updateSchema "${schema}" "${SCHEMA_URL}" "${PACKAGE_VERSION}" "${JSON_SCHEMA}" "${FILE_PATH}"