Skip to content

Commit 67ac8d2

Browse files
authored
Merge pull request #1175 from watson-developer-cloud/9520_gha
ci: Add deploy via GHA
2 parents 8f2bb5a + 11a8840 commit 67ac8d2

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support documentation.
4+
# This workflow will download a prebuilt Java version, install dependencies, build and deploy/publish a new release
5+
# For more information see: https://docs.github.com/en/actions/guides/building-and-testing-java-with-maven
6+
7+
name: Deploy and Publish
8+
9+
on:
10+
workflow_run:
11+
workflows: ["Build and Test"]
12+
branches: [ master ]
13+
types:
14+
- completed
15+
16+
# Allows you to run this workflow manually from the Actions tab
17+
workflow_dispatch:
18+
19+
jobs:
20+
deploy:
21+
if: "!contains(github.event.head_commit.message, 'skip ci')"
22+
name: Deploy and Publish
23+
env:
24+
MVN_ARGS: '-B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn'
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
with:
30+
persist-credentials: false
31+
32+
- name: Set up Java
33+
uses: actions/setup-java@v2
34+
with:
35+
java-version: '8'
36+
distribution: 'adopt'
37+
38+
- name: Build Java package
39+
run: mvn verify -fae -DskipITs -Dskip.unit.tests $MVN_ARGS
40+
41+
- name: Setup Node
42+
uses: actions/setup-node@v1
43+
with:
44+
node-version: 12
45+
46+
- name: Install Semantic Release dependencies
47+
run: |
48+
sudo apt-get install bumpversion
49+
npm install -g semantic-release
50+
npm install -g @semantic-release/changelog
51+
npm install -g @semantic-release/exec
52+
npm install -g @semantic-release/git
53+
npm install -g @semantic-release/github
54+
npm install -g @semantic-release/commit-analyzer
55+
npm install -g @semantic-release/release-notes-generator
56+
57+
- name: Publish to Git Releases and Tags
58+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
61+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
62+
run: npx semantic-release # --dry-run --branches 9520_gha
63+
64+
- name: Publish to Maven Central
65+
if: startsWith(github.ref, 'refs/tags/v')
66+
env:
67+
GHA_TAG: ${{ github.ref }} # non PR only need to get last part
68+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} # for .travis.settings.xml
69+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
70+
run: |
71+
build/setupSigning.sh
72+
build/setMavenVersion_gha.sh
73+
mvn deploy --settings build/.travis.settings.xml -DskipITs -Dskip.unit.tests -P central $MVN_ARGS
74+
75+
- name: Publish Java docs
76+
if: startsWith(github.ref, 'refs/tags/v')
77+
env:
78+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
79+
GHA_REPO_SLUG: ${{ github.repository }}
80+
GHA_BRANCH: ${{ github.ref }} # non PR only need to get last part
81+
GHA_PULL_REQUEST: ${{ github.event.number }}
82+
GHA_BUILD_NUMBER: ${{ github.run_number }}
83+
GHA_JOB_NUMBER: ${{ github.job_number }}
84+
GHA_COMMIT: ${{ github.sha }}
85+
GHA_TAG: ${{ github.ref }} # for setMavenVersion_gha
86+
run: |
87+
build/setMavenVersion_gha.sh
88+
mvn clean javadoc:aggregate $MVN_ARGS
89+
build/publish_gha.sh

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Watson APIs Java SDK
2-
[![Build Status](https://travis-ci.org/watson-developer-cloud/java-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/java-sdk)
2+
[![Build and Test](https://github.com/watson-developer-cloud/java-sdk/actions/workflows/build-test.yml/badge.svg)](https://github.com/watson-developer-cloud/java-sdk/actions/workflows/build-test.yml)
3+
[![Deploy and Publish](https://github.com/watson-developer-cloud/java-sdk/actions/workflows/deploy.yml/badge.svg)](https://github.com/watson-developer-cloud/java-sdk/actions/workflows/deploy.yml)
34
[![Slack](https://wdc-slack-inviter.mybluemix.net/badge.svg)](https://wdc-slack-inviter.mybluemix.net)
45
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.ibm.watson/ibm-watson/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.ibm.watson/ibm-watson)
56
[![CLA assistant](https://cla-assistant.io/readme/badge/watson-developer-cloud/java-sdk)](https://cla-assistant.io/watson-developer-cloud/java-sdk)
67
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
78

9+
## Deprecated builds
10+
[![Build Status](https://travis-ci.org/watson-developer-cloud/java-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/java-sdk)
11+
812
Java client library to use the [Watson APIs][wdc].
913

1014
<details>

build/publish_gha.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# This script will publish the aggregated javadocs found in the project's "target" directory.
4+
# The javadocs are committed and pushed to the git repository's gh-pages branch.
5+
# Be sure to customize this file to reflect your SDK project's settings (git url,
6+
7+
export GHA_BRANCH=${GHA_BRANCH##*/} # Get the last part for true branch name - "refs/heads/9260_gha"
8+
# Avoid publishing javadocs for a PR build
9+
if [ "$GHA_PULL_REQUEST" == "false" ] && [ "$GHA_BRANCH" ]; then
10+
printf "\n>>>>> Publishing javadoc for release build: repo=%s branch=%s build_num=%s job_num=%s pr=%s tag=%s commit=%s\n" ${GHA_REPO_SLUG} ${GHA_BRANCH} ${GHA_BUILD_NUMBER} ${GHA_JOB_NUMBER} ${GHA_PULL_REQUEST} ${GHA_TAG} ${GHA_COMMIT}
11+
12+
printf "\n>>>>> Cloning repository's gh-pages branch into directory 'gh-pages'\n"
13+
rm -fr ./gh-pages
14+
git clone --branch=gh-pages https://${GH_TOKEN}@github.com/watson-developer-cloud/java-sdk.git gh-pages > /dev/null
15+
16+
printf "\n>>>>> Finished cloning...\n"
17+
18+
pushd gh-pages
19+
20+
# Create a new directory for this branch/tag and copy the aggregated javadocs there.
21+
printf "\n>>>>> Copying aggregated javadocs to new tagged-release directory: %s\n" ${GHA_BRANCH}
22+
rm -rf docs/${GHA_BRANCH}
23+
mkdir -p docs/${GHA_BRANCH}
24+
cp -rf ../target/site/apidocs/* docs/${GHA_BRANCH}
25+
26+
printf "\n>>>>> Generating gh-pages index.html...\n"
27+
../build/generateJavadocIndex.sh > index.html
28+
29+
# Update the 'latest' symlink to point to this branch if it's a tagged release.
30+
if [ -n "$GHA_TAG" ]; then
31+
pushd docs
32+
rm latest
33+
ln -s ./${GHA_TAG} latest
34+
printf "\n>>>>> Updated 'docs/latest' symlink:\n"
35+
ls -l latest
36+
popd
37+
fi
38+
39+
printf "\n>>>>> Committing new javadoc...\n"
40+
git add -f .
41+
git commit -m "Javadoc for release ${GHA_TAG} (${GHA_COMMIT})"
42+
git push -f origin gh-pages
43+
44+
popd
45+
46+
printf "\n>>>>> Published javadoc for release build: repo=%s branch=%s build_num=%s job_num=%s\n" ${GHA_REPO_SLUG} ${GHA_BRANCH} ${GHA_BUILD_NUMBER} ${GHA_JOB_NUMBER}
47+
48+
else
49+
50+
printf "\n>>>>> Javadoc publishing bypassed for non-release build: repo=%s branch=%s build_num=%s job_num=%s pr=%s tag=%s commit=%s\n" ${GHA_REPO_SLUG} ${GHA_BRANCH} ${GHA_BUILD_NUMBER} ${GHA_JOB_NUMBER} ${GHA_PULL_REQUEST} ${GHA_TAG} ${GHA_COMMIT}
51+
52+
fi

build/setMavenVersion_gha.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# This script will check $GHA_TAG to see if we need to run maven to
4+
# set the artifact version #'s.
5+
export GHA_TAG=${GHA_TAG##*/} # Get the last part for true tag name - "refs/heads/9260_gha"
6+
7+
if [[ -n "${GHA_TAG}" ]]; then
8+
printf "\n>>>>> Setting artifact version #'s to: %s\n" ${GHA_TAG}
9+
mvn versions:set -DnewVersion=${GHA_TAG:1} -DgenerateBackupPoms=false
10+
else
11+
printf "\n>>>>> Bypassing artifact version setting for non-tagged build %s\n" ${GHA_TAG}
12+
fi
13+

0 commit comments

Comments
 (0)