Skip to content

Commit

Permalink
Update github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Feb 28, 2021
1 parent 526b8a8 commit 2e86376
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 142 deletions.
66 changes: 11 additions & 55 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,32 @@
#
# Copyright 2021 The ModiTect authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Build

name: Build & Release

on: [push, pull_request]
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build
runs-on: ubuntu-latest
if: startsWith(github.event.head_commit.message, 'Releasing version') != true

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v2.3.4

- name: Setup Java
uses: actions/setup-java@v1
uses: actions/setup-java@v1.4.3
with:
java-version: 1.8

- name: Cache Maven
uses: actions/cache@v1
uses: actions/cache@v2.1.4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build
run: |
chmod +x mvnw
./mvnw -B verify --file pom.xml
release:
name: Release
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.event.head_commit.message, '[release]')

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 1.8
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Release
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
export GPG_TTY=$(tty)
git config user.name "${{ github.event.head_commit.committer.name }}"
git config user.email "${{ github.event.head_commit.committer.email }}"
mvn -B --file pom.xml release:prepare release:perform -Drepository.url=https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
run: ./mvnw --no-transfer-progress -B --file pom.xml verify
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

on:
push:
tags:
- v*

jobs:
release:
name: Release
runs-on: ubuntu-latest

steps:
- name: Version
id: version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Checkout
uses: actions/checkout@v2.3.4

- name: Cache Maven
uses: actions/cache@v2.1.4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Setup Java
uses: actions/setup-java@v1.4.3
with:
java-version: 1.8
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Release
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
export GPG_TTY=$(tty)
./mvnw --no-transfer-progress -B --file pom.xml \
-Drepository.url=https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git \
-Dmaven.site.skip=true -Drelease=true deploy
75 changes: 75 additions & 0 deletions .github/workflows/trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Trigger

on:
workflow_dispatch:
inputs:
branch:
description: "Branch to release from"
required: true
default: "main"
version:
description: "Release version"
required: true

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Setup Java
uses: actions/setup-java@v1.4.3
with:
java-version: 1.8

- name: Cache Maven
uses: actions/cache@v2.1.4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build
run: ./mvnw --no-transfer-progress -B --file pom.xml verify

tag:
name: Tag
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v2.3.4
with:
# required for triggering release workflow on tagging
token: ${{ secrets.GIT_ACCESS_TOKEN }}

- name: Setup Java
uses: actions/setup-java@v1.4.3
with:
java-version: 1.8

- name: Cache Maven
uses: actions/cache@v2.1.4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Create tag
run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
BRANCH=${{ github.event.inputs.branch }}
VERSION=${{ github.event.inputs.version }}
echo "Releasing $VERSION from $BRANCH branch"
git checkout $BRANCH
./mvnw -B versions:set versions:commit -DnewVersion=$VERSION
git config --global user.email "moditect-release-bot@moditect.org"
git config --global user.name "moditect-release-bot"
git commit -a -m "Releasing version $VERSION"
git tag v$VERSION
git push origin $BRANCH
git push origin v$VERSION
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:project-version: 1.0.0-SNAPSHOT

image:https://github.com/{project-owner}/{project-name}/workflows/Build/badge.svg["Build Status", link="https://github.com/{project-owner}/{project-name}/actions"]
image:https://img.shields.io/maven-central/v/{project-groupId}/{project-artifactId}.svg[Download, link="https://search.maven.org/#search|ga|1|{project-artifactId}"]
image:https://img.shields.io/maven-central/v/{project-groupId}/{project-artifactId}.svg[Download, link="https://search.maven.org/#search|ga|1|g:{project-groupId} AND a:{project-artifactId}"]

---

Expand All @@ -31,7 +31,7 @@ Given a project named `foo` located at `moditect/foo`:
----
<properties>
<project.identifier>foo</project.identifier>
<project.repository>moditect/foo</project.repository>
<project.github.repository>moditect/foo</project.github.repository>
<local.repository.path>/tmp/repository</local.repository.path>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
22 changes: 12 additions & 10 deletions etc/license.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Copyright 2021 The ModiTect authors
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Copyright ${project.inceptionYear} The ModiTect authors.

http://www.apache.org/licenses/LICENSE-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading

0 comments on commit 2e86376

Please sign in to comment.