Skip to content
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
76 changes: 76 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Prepare Release

on:
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Verify release line
env:
REF_NAME: ${{ github.ref_name }}
run: |
if [ "${REF_NAME}" != "1.5" ]; then
echo "ERROR: this workflow releases swagger-core v1 and must run on branch 1.5, got ${REF_NAME}"
exit 1
fi
- uses: actions/checkout@v6
- uses: actions/create-github-app-token@v3
id: generate-token
with:
client-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Set up Python 3.10
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Set up Java 8
uses: actions/setup-java@v5
with:
java-version: 8
distribution: temurin
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Cache local Maven repository
uses: actions/cache@v5
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run prepare release script
id: prepare-release
run: |
export MY_POM_VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
if [[ ! $MY_POM_VERSION =~ ^1\. ]];
then
echo "ERROR: pom version ${MY_POM_VERSION} is not a 1.x version"
exit 1
fi
if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
then
. ./CI/prepare-release.sh
echo "PREPARE_RELEASE_OK=yes" >> $GITHUB_ENV
else
echo "not preparing release for release version: " ${MY_POM_VERSION}
echo "PREPARE_RELEASE_OK=no" >> $GITHUB_ENV
fi
echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
- name: Create Prepare Release Pull Request
uses: peter-evans/create-pull-request@v8
if: env.PREPARE_RELEASE_OK == 'yes'
with:
token: ${{ steps.generate-token.outputs.token }}
commit-message: prepare release ${{ env.SC_VERSION }}
title: 'prepare release ${{ env.SC_VERSION }}'
branch: prepare-release-${{ env.SC_VERSION }}
base: ${{ github.ref_name }}
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Release

on:
workflow_dispatch:

jobs:
build:
Comment thread
daniel-kmiecik marked this conversation as resolved.
Resolved
runs-on: ubuntu-latest
steps:
- name: Verify release line
env:
REF_NAME: ${{ github.ref_name }}
run: |
if [ "${REF_NAME}" != "1.5" ]; then
echo "ERROR: this workflow releases swagger-core v1 and must run on branch 1.5, got ${REF_NAME}"
exit 1
fi
- uses: actions/checkout@v6
- uses: actions/create-github-app-token@v3
id: generate-token
with:
client-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Set up Python 3.10
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Set up Java 8
uses: actions/setup-java@v5
with:
java-version: 8
distribution: temurin
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }}
# env var holding the passphrase; also the one maven-gpg-plugin 3.2+ reads by default
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Cache local Maven repository
uses: actions/cache@v5
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run pre release script
id: preRelease
run: |
export MY_POM_VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
if [[ ! $MY_POM_VERSION =~ ^1\. ]];
then
echo "ERROR: pom version ${MY_POM_VERSION} is not a 1.x version"
exit 1
fi
if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
then
echo "not releasing snapshot version: " ${MY_POM_VERSION}
echo "RELEASE_OK=no" >> $GITHUB_ENV
else
. ./CI/pre-release.sh
echo "RELEASE_OK=yes" >> $GITHUB_ENV
fi
echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
- name: Run maven deploy/release
if: env.RELEASE_OK == 'yes'
run: |
./mvnw --no-transfer-progress -B -Prelease deploy
- name: Run post release script
id: postRelease
if: env.RELEASE_OK == 'yes'
run: |
. ./CI/post-release.sh
- name: Create Next Snapshot Pull Request
uses: peter-evans/create-pull-request@v8
if: env.RELEASE_OK == 'yes'
with:
token: ${{ steps.generate-token.outputs.token }}
commit-message: bump snapshot ${{ env.SC_NEXT_VERSION }}-SNAPSHOT
title: 'bump snapshot ${{ env.SC_NEXT_VERSION }}-SNAPSHOT'
branch: bump-snap-${{ env.SC_NEXT_VERSION }}-SNAPSHOT
base: ${{ github.ref_name }}

env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }}
57 changes: 57 additions & 0 deletions CI/CI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Continuous integration

This file describes the release CI of the `1.5` branch (swagger-core v1, `1.6.x`). The `master` branch (2.x line) and the
`3.0.0` branch (3.x line) have their own copies of the release workflows and scripts.

### Build, test and deploy
Github actions configured in `.github/workflows`:

* maven-v1.yml : Build Test Deploy 1.5 (push to `1.5`, snapshot deploy)
* maven-v1-pulls.yml : Build Test PR 1.5 (PRs to `1.5`)
* prepare-release.yml : Prepare Release (manual)
* release.yml : Release (manual)

### Release

The workflow files have the same names on `master`, `3.0.0` and `1.5`, so the manual workflows can be run from the
`Run workflow` dropdown by selecting the `1.5` branch. Both workflows stop unless the selected branch is `1.5` and the
pom version starts with `1.`.

Differences from the 2.x/3.x scripts:

* `lastRelease.py` finds the last published `v1.*` release (paging through all releases, v1 ones are far behind).
* `releaseNotes.py` lists PRs merged to `1.5` and creates the draft release with target `1.5`.
* `publishRelease.py` publishes the draft release with target `1.5`.
* no gradle plugin, BOM, changelog, javadocs or wiki steps. README: only the "currently X-SNAPSHOT" line is bumped to the next snapshot.

#### Workflow summary

1. execute `prepare-release.yml` / `Prepare Release` for `1.5` branch
1. check and merge the Prepare Release PR pushed by previous step. Delete the branch
1. execute `release.yml` / `Release` for `1.5` branch
1. check and merge the next snapshot PR pushed by previous step. Delete the branch

#### Prepare Release

`Prepare Release` takes care of:

* create release notes out of merged PRs
* draft a release with related tag (`v1.6.x`)
* bump versions to release
* build and test maven
* push a Pull Request to `1.5` with the changes for human check.

#### Release

`Release` takes care of:

* build and test maven
* deploy/publish to maven central
* publish the previously prepared GitHub release / tag
* push PR to `1.5` for next snapshot

### Secrets

* `APP_ID` and `APP_PRIVATE_KEY`: GitHub App credentials used to obtain a token for creating the PRs
* `OSSRH_GPG_PRIVATE_KEY` and `OSSRH_GPG_PRIVATE_PASSPHRASE`: gpg key and passphrase for signing artifacts
* `MAVEN_CENTRAL_USERNAME` and `MAVEN_CENTRAL_PASSWORD`: Maven Central user/token
59 changes: 59 additions & 0 deletions CI/ghApiClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python

import os
import time
import urllib.request, urllib.error, urllib.parse
import http.client
import json

GH_BASE_URL = "https://api.github.com/"

GH_TOKEN = os.environ['GH_TOKEN']
GH_AUTH = "Bearer %s" % GH_TOKEN

def readUrl(name):
try:
request = urllib.request.Request(GH_BASE_URL + name)
request.add_header("Authorization", GH_AUTH)
content = urllib.request.urlopen(request).read()
jcont = json.loads(content)
return jcont
except urllib.error.HTTPError as e:
print(('HTTPError = ' + str(e.code)))
raise e
except urllib.error.URLError as e:
print(('URLError = ' + str(e.reason)))
raise e
except http.client.HTTPException as e:
print(('HTTPException = ' + str(e)))
raise e
except Exception:
import traceback
print(('generic exception: ' + traceback.format_exc()))
raise IOError

def postUrl(name, body):
global GH_BASE_URL
try:
time.sleep(0.05)
request = urllib.request.Request(GH_BASE_URL + name)
request.add_header("Authorization", GH_AUTH)
request.add_header("Accept", "application/vnd.github.v3+json")
data = body.encode('utf-8')
content = urllib.request.urlopen(request, data).read()
jcont = json.loads(content)
return jcont
except urllib.error.HTTPError as e:
print(('HTTPError = ' + str(e.code)))
print((str(e)))
raise e
except urllib.error.URLError as e:
print(('URLError = ' + str(e.reason)))
raise e
except http.client.HTTPException as e:
print(('HTTPException = ' + str(e)))
raise e
except Exception:
import traceback
print(('generic exception: ' + traceback.format_exc()))
raise IOError
29 changes: 29 additions & 0 deletions CI/lastRelease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python

import ghApiClient

PER_PAGE = 100

def getLastReleaseTag(prefix):
# releases are returned newest first; v1 releases are far behind the v2/v3 ones, so page through them
page = 1
while True:
content = ghApiClient.readUrl('repos/swagger-api/swagger-core/releases?per_page=%d&page=%d' % (PER_PAGE, page))
for l in content:
draft = l["draft"]
tag = l["tag_name"]
if str(draft) != 'True' and tag.startswith(prefix):
return tag[1:]
if len(content) < PER_PAGE:
return None
page += 1

# main
def main():
result = getLastReleaseTag("v1.")
if result is None:
raise SystemExit("ERROR: no published v1 release found")
print (result)

# here start main
main()
16 changes: 16 additions & 0 deletions CI/post-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

CUR=$(pwd)

SC_RELEASE_TAG="v$SC_VERSION"

#####################
### publish pre-prepared release (tag is created)
#####################
python $CUR/CI/publishRelease.py "$SC_RELEASE_TAG"

#####################
### update the version to next snapshot in maven project with set version
#####################
./mvnw versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT"
./mvnw versions:commit
11 changes: 11 additions & 0 deletions CI/pre-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

CUR=$(pwd)

export SC_VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
export SC_NEXT_VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`

#####################
### build and test maven ###
#####################
./mvnw --no-transfer-progress -B install --file pom.xml
34 changes: 34 additions & 0 deletions CI/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

CUR=$(pwd)

export SC_VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
export SC_NEXT_VERSION=`./mvnw -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py`
export SC_LAST_RELEASE

SC_RELEASE_TITLE="Swagger-core $SC_VERSION released!"
SC_RELEASE_TAG="v$SC_VERSION"

#####################
### draft release Notes with next release after last release, with tag
#####################
python $CUR/CI/releaseNotes.py "$SC_LAST_RELEASE" "$SC_RELEASE_TITLE" "$SC_RELEASE_TAG"

#####################
### update the version to release in maven project with set version
#####################
./mvnw versions:set -DnewVersion=$SC_VERSION
./mvnw versions:commit

#####################
### update the "build from source" version in readme to the next snapshot ###
#####################
sc_find="currently $SC_VERSION-SNAPSHOT"
sc_replace="currently $SC_NEXT_VERSION-SNAPSHOT"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/README.md

#####################
### build and test maven ###
#####################
./mvnw --no-transfer-progress -B install --file pom.xml
Loading
Loading