From cd099bec7706e8a3dcb369a2689a2f73469bcf53 Mon Sep 17 00:00:00 2001 From: frantuma Date: Tue, 18 Apr 2023 15:10:58 +0200 Subject: [PATCH] migrate CI to GitHub Actions --- .github/topissuebot.yml | 3 + .github/workflows/codeql-analysis.yml | 54 ++++++++++++++ .github/workflows/maven-pulls.yml | 31 ++++++++ .github/workflows/maven-v1-pulls.yml | 30 ++++++++ .github/workflows/maven-v1.yml | 45 ++++++++++++ .github/workflows/maven.yml | 54 ++++++++++++++ .github/workflows/next-snapshot-v1.yml | 87 ++++++++++++++++++++++ .github/workflows/next-snapshot.yml | 87 ++++++++++++++++++++++ .github/workflows/prepare-release-v1.yml | 66 +++++++++++++++++ .github/workflows/prepare-release.yml | 66 +++++++++++++++++ .github/workflows/release-v1.yml | 91 ++++++++++++++++++++++++ .github/workflows/release.yml | 91 ++++++++++++++++++++++++ CI/CI.md | 87 ++++++++++++++++++++++ CI/ghApiClient.py | 58 +++++++++++++++ CI/lastRelease.py | 19 +++++ CI/lastReleaseV1.py | 19 +++++ CI/post-nextsnap-v1.sh | 24 +++++++ CI/post-nextsnap.sh | 24 +++++++ CI/post-release-v1.sh | 17 +++++ CI/post-release.sh | 17 +++++ CI/pre-release-v1.sh | 18 +++++ CI/pre-release.sh | 18 +++++ CI/prepare-release-v1.sh | 43 +++++++++++ CI/prepare-release.sh | 45 ++++++++++++ CI/publishRelease.py | 27 +++++++ CI/publishReleaseV1.py | 27 +++++++ CI/releaseNotes.py | 51 +++++++++++++ CI/releaseNotesV1.py | 51 +++++++++++++ pom.xml | 89 +++++++++++++++++++++-- 29 files changed, 1334 insertions(+), 5 deletions(-) create mode 100644 .github/topissuebot.yml create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/maven-pulls.yml create mode 100644 .github/workflows/maven-v1-pulls.yml create mode 100644 .github/workflows/maven-v1.yml create mode 100644 .github/workflows/maven.yml create mode 100644 .github/workflows/next-snapshot-v1.yml create mode 100644 .github/workflows/next-snapshot.yml create mode 100644 .github/workflows/prepare-release-v1.yml create mode 100644 .github/workflows/prepare-release.yml create mode 100644 .github/workflows/release-v1.yml create mode 100644 .github/workflows/release.yml create mode 100644 CI/CI.md create mode 100755 CI/ghApiClient.py create mode 100755 CI/lastRelease.py create mode 100755 CI/lastReleaseV1.py create mode 100755 CI/post-nextsnap-v1.sh create mode 100755 CI/post-nextsnap.sh create mode 100755 CI/post-release-v1.sh create mode 100755 CI/post-release.sh create mode 100755 CI/pre-release-v1.sh create mode 100755 CI/pre-release.sh create mode 100755 CI/prepare-release-v1.sh create mode 100755 CI/prepare-release.sh create mode 100755 CI/publishRelease.py create mode 100755 CI/publishReleaseV1.py create mode 100755 CI/releaseNotes.py create mode 100755 CI/releaseNotesV1.py diff --git a/.github/topissuebot.yml b/.github/topissuebot.yml new file mode 100644 index 00000000..f48b026e --- /dev/null +++ b/.github/topissuebot.yml @@ -0,0 +1,3 @@ +labelName: ":thumbsup: Top Issue!" +labelColor: "f442c2" +numberOfIssuesToLabel: 5 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..5ffbb217 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,54 @@ +name: "Code scanning - action" + +on: + push: + branches: [master, v1] + pull_request: + # The branches below must be a subset of the branches above + branches: [master, v1] + schedule: + - cron: '0 19 * * 1' + +jobs: + CodeQL-Build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + + # If this run was triggered by a pull request event, then checkout + # the head of the pull request instead of the merge commit. + - run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + # Override language selection by uncommenting this and choosing your languages + with: + languages: java + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/maven-pulls.yml b/.github/workflows/maven-pulls.yml new file mode 100644 index 00000000..5f141fe2 --- /dev/null +++ b/.github/workflows/maven-pulls.yml @@ -0,0 +1,31 @@ +name: Build Test PR + +on: + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 8, 9 ] + + steps: + - uses: actions/checkout@v2 + - name: Set up Java + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'zulu' + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Build with Maven + run: | + mvn --no-transfer-progress -B verify --file pom.xml diff --git a/.github/workflows/maven-v1-pulls.yml b/.github/workflows/maven-v1-pulls.yml new file mode 100644 index 00000000..62bb2bbf --- /dev/null +++ b/.github/workflows/maven-v1-pulls.yml @@ -0,0 +1,30 @@ +name: Build Test PR v1 + +on: + pull_request: + branches: [ "v1" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 8 ] + + steps: + - uses: actions/checkout@v2 + - name: Set up Java + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'zulu' + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Build with Maven + run: mvn -B verify --file pom.xml diff --git a/.github/workflows/maven-v1.yml b/.github/workflows/maven-v1.yml new file mode 100644 index 00000000..d0be1f29 --- /dev/null +++ b/.github/workflows/maven-v1.yml @@ -0,0 +1,45 @@ +name: Build Test Deploy v1 + +on: + push: + branches: [ "v1" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 8 ] + + steps: + - uses: actions/checkout@v2 + - name: Set up Java + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Build with Maven, Deploy snapshot to maven central + run: | + mvn --no-transfer-progress -B verify --file pom.xml + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + echo "POM VERSION" ${MY_POM_VERSION} + if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]]; + then + mvn --no-transfer-progress -B clean deploy + else + echo "not deploying release: " ${MY_POM_VERSION} + fi + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000..ecc03140 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,54 @@ +name: Build Test Deploy master + +on: + push: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 8, 9 ] + + steps: + - uses: actions/checkout@v2 + - name: Set up Java + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Build with Maven, Deploy snapshot to maven central + run: | + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + echo "POM VERSION" ${MY_POM_VERSION} + if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]]; + then + mvn --no-transfer-progress -B verify --file pom.xml + export MY_JAVA_VERSION=`java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1` + echo "JAVA VERSION" ${MY_JAVA_VERSION} + if [[ ${MY_JAVA_VERSION} == "8" ]]; + then + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + echo "POM VERSION" ${MY_POM_VERSION} + mvn --no-transfer-progress -B clean deploy + else + echo "not deploying on java version: " ${MY_JAVA_VERSION} + fi + else + echo "not building and maven publishing project as it is a release version: " ${MY_JAVA_VERSION} + fi + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} diff --git a/.github/workflows/next-snapshot-v1.yml b/.github/workflows/next-snapshot-v1.yml new file mode 100644 index 00000000..25f74e63 --- /dev/null +++ b/.github/workflows/next-snapshot-v1.yml @@ -0,0 +1,87 @@ +name: Next Snapshot V1 + +on: + workflow_dispatch: + branches: ["v1"] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Python 2.7 + uses: actions/setup-python@v2 + with: + python-version: 2.7 + - name: Set up Java 8 + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + 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 GPG_TTY=$(tty) + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]]; + then + echo "not releasing snapshot version: " ${MY_POM_VERSION} + echo "RELEASE_OK=no" >> $GITHUB_ENV + else + . ./CI/pre-release-v1.sh + echo "RELEASE_OK=yes" >> $GITHUB_ENV + fi + echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV + echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV + echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV + - name: configure git user email + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + git config --global hub.protocol https + git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/swagger-api/swagger-inflector.git + - name: Checkout v1 + uses: actions/checkout@v2 + with: + ref: "v1" + fetch-depth: 0 + - name: Run next snapshot script + id: postRelease + if: env.RELEASE_OK == 'yes' + run: | + . ./CI/post-nextsnap-v1.sh + - name: Create Next Snapshot Pull Request + uses: peter-evans/create-pull-request@v4 + 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 + + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SC_VERSION: + SC_NEXT_VERSION: + GPG_PRIVATE_KEY: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }} diff --git a/.github/workflows/next-snapshot.yml b/.github/workflows/next-snapshot.yml new file mode 100644 index 00000000..5e13328a --- /dev/null +++ b/.github/workflows/next-snapshot.yml @@ -0,0 +1,87 @@ +name: Next Snapshot + +on: + workflow_dispatch: + branches: ["master"] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Python 2.7 + uses: actions/setup-python@v2 + with: + python-version: 2.7 + - name: Set up Java 8 + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + 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 GPG_TTY=$(tty) + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + 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 + echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV + - name: configure git user email + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + git config --global hub.protocol https + git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/swagger-api/swagger-inflector.git + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: "master" + fetch-depth: 0 + - name: Run next snapshot script + id: postRelease + if: env.RELEASE_OK == 'yes' + run: | + . ./CI/post-nextsnap.sh + - name: Create Next Snapshot Pull Request + uses: peter-evans/create-pull-request@v4 + 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 + + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SC_VERSION: + SC_NEXT_VERSION: + GPG_PRIVATE_KEY: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }} diff --git a/.github/workflows/prepare-release-v1.yml b/.github/workflows/prepare-release-v1.yml new file mode 100644 index 00000000..12c45a56 --- /dev/null +++ b/.github/workflows/prepare-release-v1.yml @@ -0,0 +1,66 @@ +name: Prepare Release V1 + +on: + workflow_dispatch: + branches: ["v1"] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Python 2.7 + uses: actions/setup-python@v2 + with: + python-version: 2.7 + - name: Set up Java 8 + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + 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=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]]; + then + . ./CI/prepare-release-v1.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@v4 + 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 }} + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SC_VERSION: + SC_NEXT_VERSION: diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 00000000..b8f7da9a --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,66 @@ +name: Prepare Release + +on: + workflow_dispatch: + branches: ["master"] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Python 2.7 + uses: actions/setup-python@v2 + with: + python-version: 2.7 + - name: Set up Java 8 + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + 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=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + 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@v4 + 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 }} + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SC_VERSION: + SC_NEXT_VERSION: diff --git a/.github/workflows/release-v1.yml b/.github/workflows/release-v1.yml new file mode 100644 index 00000000..6bd4776d --- /dev/null +++ b/.github/workflows/release-v1.yml @@ -0,0 +1,91 @@ +name: Release V1 + +on: + workflow_dispatch: + branches: ["v1"] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Python 2.7 + uses: actions/setup-python@v2 + with: + python-version: 2.7 + - name: Set up Java 8 + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + 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 GPG_TTY=$(tty) + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]]; + then + echo "not releasing snapshot version: " ${MY_POM_VERSION} + echo "RELEASE_OK=no" >> $GITHUB_ENV + else + . ./CI/pre-release-v1.sh + echo "RELEASE_OK=yes" >> $GITHUB_ENV + fi + echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV + echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV + echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV + - name: configure git user email + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + git config --global hub.protocol https + git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/swagger-api/swagger-inflector.git + - name: Run maven deploy/release (action-maven-publish) + uses: samuelmeuli/action-maven-publish@v1 + if: env.RELEASE_OK == 'yes' + with: + gpg_private_key: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }} + gpg_passphrase: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }} + nexus_username: ${{ secrets.OSSRH_USERNAME }} + nexus_password: ${{ secrets.OSSRH_TOKEN }} + maven_profiles: "release" + - name: Run post release script + id: postRelease + if: env.RELEASE_OK == 'yes' + run: | + . ./CI/post-release-v1.sh + - name: Create Next Snapshot Pull Request + uses: peter-evans/create-pull-request@v4 + 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 + + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SC_VERSION: + SC_NEXT_VERSION: + GPG_PRIVATE_KEY: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..ce73abd7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,91 @@ +name: Release + +on: + workflow_dispatch: + branches: ["master"] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Python 2.7 + uses: actions/setup-python@v2 + with: + python-version: 2.7 + - name: Set up Java 8 + uses: actions/setup-java@v2 + with: + java-version: 8 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Cache local Maven repository + uses: actions/cache@v2 + 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 GPG_TTY=$(tty) + export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` + 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 + echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV + - name: configure git user email + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + git config --global hub.protocol https + git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/swagger-api/swagger-inflector.git + - name: Run maven deploy/release (action-maven-publish) + uses: samuelmeuli/action-maven-publish@v1 + if: env.RELEASE_OK == 'yes' + with: + gpg_private_key: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }} + gpg_passphrase: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }} + nexus_username: ${{ secrets.OSSRH_USERNAME }} + nexus_password: ${{ secrets.OSSRH_TOKEN }} + maven_profiles: "release" + - 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@v4 + 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 + + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SC_VERSION: + SC_NEXT_VERSION: + GPG_PRIVATE_KEY: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }} diff --git a/CI/CI.md b/CI/CI.md new file mode 100644 index 00000000..ca29820c --- /dev/null +++ b/CI/CI.md @@ -0,0 +1,87 @@ +## Continuous integration + +### Build, test and deploy +Swagger Inflector uses Github actions to run jobs/checks building, testing and deploying snapshots on push and PR events. + +These github actions are configured in `.github/workflows`: + +* maven.yml : Build Test Deploy master +* maven-pulls.yml Build Test PR +* maven-v1.yml : Build Test Deploy v1 (must exist in in `v1` branch) +* maven-v1-pulls.yml Build Test PR v1 (must exist in in `v1` branch) + + +These actions use available actions in combination with short bash scripts. + +### Release + +Releases are semi-automated and consist in 2 actions using available public actions in combination with bash and python scripts. +**TODO**: Python code is used for historical reasons to execute GitHub APIs calls, in general a more consistent environment would +be more maintainable e.g. implementing a custom JavaScript or Docker Container GitHub Action and/or a bash only script(s). + +#### Workflow summary + +1. execute `prepare-release.yml` / `Prepare Release` for `master` branch +1. check and merge the Prepare Release PR pushed by previous step. Delete the branch +1. execute `release.yml` / `Release` for `master` branch +1. check and merge the next snaphot PR pushed by previous step. Delete the branch + +#### Prepare Release + +The first action to execute is `prepare-release.yml` / `Prepare Release` for master, and +`prepare-release-v1.yml` / `Prepare Release V1` for `v1` branch. + +This is triggered by manually executing the action, selecting `Actions` in project GitHub UI, then `Prepare Release` workflow +and clicking `Run Workflow` (or `Prepare Release V1` and selecting `v1` in the dropdown) + +`Prepare Release` takes care of: + +* create release notes out of merged PRs +* Draft a release with related tag +* bump versions to release, and update all affected files +* build and test maven +* push a Pull Request with the changes for human check. + +After the PR checks complete, the PR can me merged, and the second phase `Release` started. + +#### Release + +Once prepare release PR has been merged, the second phase is provided by `release.yml` / `Release` actions for master, and +`release-v1.yml` / `Release V1` for `v1` branch. + +This is triggered by manually executing the action, selecting `Actions` in project GitHub UI, then `Release` workflow +and clicking `Run Workflow` (or `Release V1` and selecting `v1` in the dropdown) + +`Release` takes care of: + +* build and test maven +* deploy/publish to maven central +* publish the previously prepared GitHub release / tag +* push PR for next snapshot + + +### Secrets + +GitHub Actions make use of `Secrets` which can be configured either with Repo or Organization scope; the needed secrets are the following: + +* `APP_ID` and APP_PRIVATE_KEY`: these are the values provided by an account configured GitHub App, allowing to obtain a GitHub token +different from the default used in GitHub Actions (which does not allow to "chain" actions).Actions + +The GitHub App must be configured as detailed in [this doc](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens). + +See also [here](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs) + +* `OSSRH_GPG_PRIVATE_KEY` and `OSSRH_GPG_PRIVATE_PASSPHRASE` : gpg key and passphrase to be used for sonatype releases +GPG private key and passphrase defined to be used for sonatype deployments, as detailed in +https://central.sonatype.org/pages/working-with-pgp-signatures.html (I'd say with email matching the one of the sonatype account of point 1 + +* `OSSRH_USERNAME` and `OSSRH_TOKEN`: sonatype user/token + + + + + + + + + diff --git a/CI/ghApiClient.py b/CI/ghApiClient.py new file mode 100755 index 00000000..76bb1deb --- /dev/null +++ b/CI/ghApiClient.py @@ -0,0 +1,58 @@ +#!/usr/bin/python + +import os +import time +import urllib2 +import httplib +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 = urllib2.Request(GH_BASE_URL + name) + request.add_header("Authorization", GH_AUTH) + content = urllib2.urlopen(request).read() + jcont = json.loads(content) + return jcont; + except urllib2.HTTPError, e: + print 'HTTPError = ' + str(e.code) + raise e + except urllib2.URLError, e: + print 'URLError = ' + str(e.reason) + raise e + except httplib.HTTPException, 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 = urllib2.Request(GH_BASE_URL + name) + request.add_header("Authorization", GH_AUTH) + request.add_header("Accept", "application/vnd.github.v3+json") + content = urllib2.urlopen(request, body).read() + jcont = json.loads(content) + return jcont; + except urllib2.HTTPError, e: + print 'HTTPError = ' + str(e.code) + print str(e) + raise e + except urllib2.URLError, e: + print 'URLError = ' + str(e.reason) + raise e + except httplib.HTTPException, e: + print 'HTTPException = ' + str(e) + raise e + except Exception: + import traceback + print 'generic exception: ' + traceback.format_exc() + raise IOError diff --git a/CI/lastRelease.py b/CI/lastRelease.py new file mode 100755 index 00000000..7ab25e3d --- /dev/null +++ b/CI/lastRelease.py @@ -0,0 +1,19 @@ +#!/usr/bin/python + +import ghApiClient + +def getLastReleaseTag(): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases') + for l in content: + draft = l["draft"] + tag = l["tag_name"] + if str(draft) != 'True' and tag.startswith("v2"): + return tag[1:] + +# main +def main(): + result = getLastReleaseTag() + print result + +# here start main +main() diff --git a/CI/lastReleaseV1.py b/CI/lastReleaseV1.py new file mode 100755 index 00000000..eaea9b1b --- /dev/null +++ b/CI/lastReleaseV1.py @@ -0,0 +1,19 @@ +#!/usr/bin/python + +import ghApiClient + +def getLastReleaseTag(): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases') + for l in content: + draft = l["draft"] + tag = l["tag_name"] + if str(draft) != 'True' and tag.startswith("v1"): + return tag[1:] + +# main +def main(): + result = getLastReleaseTag() + print result + +# here start main +main() diff --git a/CI/post-nextsnap-v1.sh b/CI/post-nextsnap-v1.sh new file mode 100755 index 00000000..853a79cc --- /dev/null +++ b/CI/post-nextsnap-v1.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +CUR=$(pwd) +TMPDIR="$(dirname -- "${0}")" + +SC_RELEASE_TAG="v$SC_VERSION" + +##################### +### update the version to next snapshot in maven project with set version +##################### +mvn versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT" +mvn versions:commit + +##################### +### update all other versions in files around to the new release, including readme ### +##################### +sc_find="$SC_LAST_RELEASE" +sc_replace="$SC_VERSION" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/README.md + +sc_find="$SC_VERSION-SNAPSHOT<\/version>" +sc_replace="$SC_VERSION<\/version>" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/scripts/pom.xml + diff --git a/CI/post-nextsnap.sh b/CI/post-nextsnap.sh new file mode 100755 index 00000000..853a79cc --- /dev/null +++ b/CI/post-nextsnap.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +CUR=$(pwd) +TMPDIR="$(dirname -- "${0}")" + +SC_RELEASE_TAG="v$SC_VERSION" + +##################### +### update the version to next snapshot in maven project with set version +##################### +mvn versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT" +mvn versions:commit + +##################### +### update all other versions in files around to the new release, including readme ### +##################### +sc_find="$SC_LAST_RELEASE" +sc_replace="$SC_VERSION" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/README.md + +sc_find="$SC_VERSION-SNAPSHOT<\/version>" +sc_replace="$SC_VERSION<\/version>" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/scripts/pom.xml + diff --git a/CI/post-release-v1.sh b/CI/post-release-v1.sh new file mode 100755 index 00000000..d849ec25 --- /dev/null +++ b/CI/post-release-v1.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +CUR=$(pwd) +TMPDIR="$(dirname -- "${0}")" + +SC_RELEASE_TAG="v$SC_VERSION" + +##################### +### publish pre-prepared release (tag is created) +##################### +python $CUR/CI/publishReleaseV1.py "$SC_RELEASE_TAG" + +##################### +### update the version to next snapshot in maven project with set version +##################### +mvn versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT" +mvn versions:commit diff --git a/CI/post-release.sh b/CI/post-release.sh new file mode 100755 index 00000000..d9b55496 --- /dev/null +++ b/CI/post-release.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +CUR=$(pwd) +TMPDIR="$(dirname -- "${0}")" + +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 +##################### +mvn versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT" +mvn versions:commit diff --git a/CI/pre-release-v1.sh b/CI/pre-release-v1.sh new file mode 100755 index 00000000..be767875 --- /dev/null +++ b/CI/pre-release-v1.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +CUR=$(pwd) + +export SC_VERSION=`mvn -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=`mvn -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_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +#SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +SC_LAST_RELEASE=`python $CUR/CI/lastReleaseV1.py` + + +SC_RELEASE_TAG="v$SC_VERSION" + + +##################### +### build and test maven ### +##################### +mvn --no-transfer-progress -B install --file pom.xml diff --git a/CI/pre-release.sh b/CI/pre-release.sh new file mode 100755 index 00000000..c4da53de --- /dev/null +++ b/CI/pre-release.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +CUR=$(pwd) + +export SC_VERSION=`mvn -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=`mvn -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_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +#SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py` + + +SC_RELEASE_TAG="v$SC_VERSION" + + +##################### +### build and test maven ### +##################### +mvn --no-transfer-progress -B install --file pom.xml diff --git a/CI/prepare-release-v1.sh b/CI/prepare-release-v1.sh new file mode 100755 index 00000000..8c771069 --- /dev/null +++ b/CI/prepare-release-v1.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +CUR=$(pwd) + +export SC_VERSION=`mvn -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=`mvn -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_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +#SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +SC_LAST_RELEASE=`python $CUR/CI/lastReleaseV1.py` + + + +SC_RELEASE_TITLE="Swagger-inflector $SC_VERSION released!" +SC_RELEASE_TAG="v$SC_VERSION" + + +##################### +### draft release Notes with next release after last release, with tag +##################### +python $CUR/CI/releaseNotesV1.py "$SC_LAST_RELEASE" "$SC_RELEASE_TITLE" "$SC_RELEASE_TAG" + +##################### +### update the version to release in maven project with set version +##################### +mvn versions:set -DnewVersion=$SC_VERSION +mvn versions:commit + +##################### +### update all other versions in files around to the new release, including readme ### +##################### +sc_find="$SC_LAST_RELEASE" +sc_replace="$SC_VERSION" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/README.md + +sc_find="$SC_VERSION-SNAPSHOT<\/version>" +sc_replace="$SC_VERSION<\/version>" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/scripts/pom.xml + +##################### +### build and test maven ### +##################### +mvn --no-transfer-progress -B install --file pom.xml + diff --git a/CI/prepare-release.sh b/CI/prepare-release.sh new file mode 100755 index 00000000..2a286638 --- /dev/null +++ b/CI/prepare-release.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +CUR=$(pwd) + +export SC_VERSION=`mvn -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=`mvn -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_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +#SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec` +SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py` + + + +SC_RELEASE_TITLE="Swagger-inflector $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 +##################### +mvn versions:set -DnewVersion=$SC_VERSION +mvn versions:commit + +##################### +### update all other versions in files around to the new release, including readme ### +##################### +sc_find="$SC_LAST_RELEASE" +sc_replace="$SC_VERSION" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/README.md + +sc_find="$SC_VERSION-SNAPSHOT<\/version>" +sc_replace="$SC_VERSION<\/version>" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/scripts/pom.xml + + + +##################### +### build and test maven ### +##################### +mvn --no-transfer-progress -B install --file pom.xml + diff --git a/CI/publishRelease.py b/CI/publishRelease.py new file mode 100755 index 00000000..0917ed25 --- /dev/null +++ b/CI/publishRelease.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +import sys +import ghApiClient + +def lastReleaseId(tag): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases') + for l in content: + draft = l["draft"] + draft_tag = l["tag_name"] + if str(draft) == 'True' and tag == draft_tag: + return l["id"] + +def publishRelease(tag): + id = lastReleaseId(tag) + payload = "{\"tag_name\":\"" + tag + "\", " + payload += "\"draft\":" + "false" + ", " + payload += "\"target_commitish\":\"" + "master" + "\"}" + content = ghApiClient.postUrl('repos/swagger-api/swagger-inflector/releases/' + str(id), payload) + return content + +# main +def main(tag): + publishRelease (tag) + +# here start main +main(sys.argv[1]) diff --git a/CI/publishReleaseV1.py b/CI/publishReleaseV1.py new file mode 100755 index 00000000..9dcd953a --- /dev/null +++ b/CI/publishReleaseV1.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +import sys +import ghApiClient + +def lastReleaseId(tag): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases') + for l in content: + draft = l["draft"] + draft_tag = l["tag_name"] + if str(draft) == 'True' and tag == draft_tag: + return l["id"] + +def publishRelease(tag): + id = lastReleaseId(tag) + payload = "{\"tag_name\":\"" + tag + "\", " + payload += "\"draft\":" + "false" + ", " + payload += "\"target_commitish\":\"" + "v1" + "\"}" + content = ghApiClient.postUrl('repos/swagger-api/swagger-inflector/releases/' + str(id), payload) + return content + +# main +def main(tag): + publishRelease (tag) + +# here start main +main(sys.argv[1]) diff --git a/CI/releaseNotes.py b/CI/releaseNotes.py new file mode 100755 index 00000000..45e3f998 --- /dev/null +++ b/CI/releaseNotes.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +import sys +import json +from datetime import datetime +import ghApiClient + +def allPulls(releaseDate): + + result = "" + + baseurl = "https://api.github.com/repos/swagger-api/swagger-inflector/pulls/" + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/pulls?state=closed&base=master&per_page=100') + for l in content: + stripped = l["url"][len(baseurl):] + mergedAt = l["merged_at"] + if mergedAt is not None: + if datetime.strptime(mergedAt, '%Y-%m-%dT%H:%M:%SZ') > releaseDate: + if not l['title'].startswith("bump snap"): + result += '\n' + result += "* " + l['title'] + " (#" + stripped + ")" + return result + + +def lastReleaseDate(tag): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases/tags/' + tag) + publishedAt = content["published_at"] + return datetime.strptime(publishedAt, '%Y-%m-%dT%H:%M:%SZ') + + +def addRelease(release_title, tag, content): + payload = "{\"tag_name\":\"" + tag + "\", " + payload += "\"name\":" + json.dumps(release_title) + ", " + payload += "\"body\":" + json.dumps(content) + ", " + payload += "\"draft\":" + "true" + ", " + payload += "\"prerelease\":" + "false" + ", " + payload += "\"target_commitish\":\"" + "master" + "\"}" + content = ghApiClient.postUrl('repos/swagger-api/swagger-inflector/releases', payload) + return content + +def getReleases(): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases') + return content + +# main +def main(last_release, release_title, tag): + result = allPulls(lastReleaseDate('v' + last_release)) + addRelease (release_title, tag, result) + +# here start main +main(sys.argv[1], sys.argv[2], sys.argv[3]) diff --git a/CI/releaseNotesV1.py b/CI/releaseNotesV1.py new file mode 100755 index 00000000..cb6f734a --- /dev/null +++ b/CI/releaseNotesV1.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +import sys +import json +from datetime import datetime +import ghApiClient + +def allPulls(releaseDate): + + result = "" + + baseurl = "https://api.github.com/repos/swagger-api/swagger-inflector/pulls/" + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/pulls?state=closed&base=v1&per_page=100') + for l in content: + stripped = l["url"][len(baseurl):] + mergedAt = l["merged_at"] + if mergedAt is not None: + if datetime.strptime(mergedAt, '%Y-%m-%dT%H:%M:%SZ') > releaseDate: + if not l['title'].startswith("bump snap"): + result += '\n' + result += "* " + l['title'] + " (#" + stripped + ")" + return result + + +def lastReleaseDate(tag): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases/tags/' + tag) + publishedAt = content["published_at"] + return datetime.strptime(publishedAt, '%Y-%m-%dT%H:%M:%SZ') + + +def addRelease(release_title, tag, content): + payload = "{\"tag_name\":\"" + tag + "\", " + payload += "\"name\":" + json.dumps(release_title) + ", " + payload += "\"body\":" + json.dumps(content) + ", " + payload += "\"draft\":" + "true" + ", " + payload += "\"prerelease\":" + "false" + ", " + payload += "\"target_commitish\":\"" + "v1" + "\"}" + content = ghApiClient.postUrl('repos/swagger-api/swagger-inflector/releases', payload) + return content + +def getReleases(): + content = ghApiClient.readUrl('repos/swagger-api/swagger-inflector/releases') + return content + +# main +def main(last_release, release_title, tag): + result = allPulls(lastReleaseDate('v' + last_release)) + addRelease (release_title, tag, result) + +# here start main +main(sys.argv[1], sys.argv[2], sys.argv[3]) diff --git a/pom.xml b/pom.xml index 80bd3ac8..b11f610b 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,16 @@ scm:git:git@github.com:swagger-api/swagger-inflector.git https://github.com/swagger-api/swagger-inflector + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + 2.2.0 @@ -117,7 +127,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.0.0 integration-test @@ -198,8 +208,25 @@ maven-gpg-plugin 1.6 - release - sign + + --pinentry-mode + loopback + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + https://oss.sonatype.org/ + true + 30 + @@ -281,6 +308,34 @@ + + release + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + + --pinentry-mode + loopback + + + + + sign-artifacts + verify + + sign + + + + + + + target/site @@ -468,9 +523,31 @@ 3.1.4 + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + false + + + + sonatype-releases + https://oss.sonatype.org/content/repositories/releases + + false + + + true + + + - 1.6.9 - 1.0.64 + 1.6.10 + 1.0.65 2.14.2 2.12.2 1.9.2 @@ -487,5 +564,7 @@ 1.4.5 1.7.36 + UTF-8 + https://oss.sonatype.org/content/repositories/snapshots/