Skip to content

Commit

Permalink
Cutover to Gradle
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Pope <[email protected]>
  • Loading branch information
jobarr-amzn and popematt committed Nov 10, 2022
1 parent 57bd49b commit 39bac87
Show file tree
Hide file tree
Showing 24 changed files with 904 additions and 676 deletions.
99 changes: 99 additions & 0 deletions .github/actions/inspect-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# With a bit of work, this reusable composite action could be used by ANY of our repos
# that use semantic versioned releases. In order to make it reusable in other repos, we
# need to move it to a separate repo so that it can be versioned independently of ion-java.
#
# See https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
#
# However, the more maintainable long-term solution is to rewrite this action as a
# Javascript-based action.
# See https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action

name: Inspect Version

description: >
Inspects whether the version is a release version (i.e. has no "-SNAPSHOT" or "-beta"
suffixes) and whether the release version is greater than the most recent release on GitHub.
The action can optionally have an outcome of 'failure' if the version is a release version
that is not valid to release (i.e. not greater than latest existing release).
When using this action, you should provide a github API auth token in the environment to
prevent being throttled by the GitHub API and to ensure that the action can read the
latest release of the repository, if the repository is private.
Example usage:
```yaml
- uses: ./.github/actions/inspect-version
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
with:
project_version: $\{{ env.PROJECT_VERSION }}
repo: amzn/ion-java
fail_if_invalid: true
```
inputs:
project_version:
description: The semantic version of the project.
required: true
repo:
description: The source repo in 'org/repo-name' form
required: true
fail_if_invalid:
description: Whether the action should fail if the conditions are not met.
required: false
default: 'false'

outputs:
is_newest:
description: Whether or not the project version is greater than the most recent existing version
value: ${{ steps.inspection.outputs.is_newest }}
is_release:
description: Whether or not the version is a release version
value: ${{ steps.inspection.outputs.is_release }}
is_valid_to_release:
description: Whether or not the version is valid to release
value: ${{ steps.inspection.outputs.is_release == 'true' && steps.inspection.outputs.is_newest == 'true' }}

runs:
using: composite
steps:
- name: Get latest release version
# TODO: Consider handling cases where most recent release is not the "latest"
# This step assumes that the most recent release will have the highest version number.
# That is usually true, but it is NOT guaranteed.
shell: bash
run: |
echo "LATEST_RELEASE_VERSION=$(gh release view -R "${{ inputs.repo }}" --json tagName --jq '.tagName')" >> $GITHUB_ENV
- name: Compare the library version with the latest release version
# TODO: Replace this with a stricter check that the library version is one of the three
# possible subsequent versions. E.g. if latest version is 1.2.3, then library version
# should be one of 1.2.4, 1.3.0, or 2.0.0
id: is-greater-version
uses: popematt/compare-semvers@v1
with:
first: ${{ inputs.project_version }}
second: ${{ env.LATEST_RELEASE_VERSION }}
- name: Inspect Version
id: inspection
shell: bash
run: |
if [[ "${{ steps.is-greater-version.outputs.result }}" == 1 ]]; then
IS_NEWER=true;
else
IS_NEWER=false;
fi
echo "Is Newest? $IS_NEWER";
echo "is_newest=$IS_NEWER" >> $GITHUB_OUTPUT;
pattern='^v?[0-9]+\.[0-9]+\.[0-9]+$'
if [[ "${{ inputs.project_version }}" =~ $pattern ]]; then
IS_RELEASE=true;
else
IS_RELEASE=false;
fi
echo "Is Release? $IS_RELEASE";
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT;
- name: Exit with Error
if: ${{ inputs.fail_if_invalid == 'true' && steps.inspection.outputs.is_newest != 'true' && steps.inspection.outputs.is_release == 'true' }}
shell: bash
run: exit 1

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
path: ion-java-new

- name: Build ion-java from the new commit
run: cd ion-java-new && git submodule init && git submodule update && mvn clean install
run: cd ion-java-new && git submodule init && git submodule update && ./gradlew clean publishToMavenLocal

- name: Checkout ion-java-benchmark-cli
uses: actions/checkout@v2
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
path: ion-java

- name: Build ion-java from the previous commit
run: cd ion-java && git submodule init && git submodule update && mvn clean install
run: cd ion-java && git submodule init && git submodule update && ./gradlew clean publishToMavenLocal

- name: Build ion-java-benchmark-cli
run: cd ion-java-benchmark-cli && mvn clean install
Expand Down
50 changes: 29 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,46 @@ on:
pull_request:
branches: [ master ]


jobs:
test:
build:
needs: check-version
runs-on: ubuntu-latest
strategy:
matrix:
java: [8, 9, 10, 11]
java: [8, 11]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Use java ${{ matrix.java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'zulu'
distribution: 'corretto'
java-version: ${{ matrix.java }}
- run: mvn test
- run: mvn package -f ion-java-cli/pom.xml
- run: java -jar ion-java-cli/target/ion-java-cli-1.0.jar version
- run: ./gradlew build
- run: ./ion-test-driver-run version

check-version:
# Ensures that the version is not a release (i.e. -SNAPSHOT) or if it is a release version,
# ensures that the version is a later version number than the existing releases.
# See limitations at:
# https://github.com/amzn/ion-java/blob/master/.github/actions/inspect-version/action.yml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Project Version
run: |
echo "PROJECT_VERSION=v$(<project.version)" >> $GITHUB_ENV
- uses: ./.github/actions/inspect-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo: amzn/ion-java
project_version: ${{ env.PROJECT_VERSION }}
fail_if_invalid: true

report-generation:
needs: check-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -36,18 +55,7 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 11
- run: mvn test site
- run: ./gradlew check
- uses: codecov/codecov-action@v1
with:
file: target/site/jacoco/jacoco.xml
- name: deploy gh-pages
if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }}
uses: JamesIves/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: "./target/site"




file: build/reports/jacoco/test/jacocoTestReport.xml
83 changes: 83 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This workflow runs when a commit is pushed to 'master' that has a change to the
# 'project.version' file. Since we have a branch protection rule for 'master', a push
# event is functionally the same as a merged PR event.
#
# If the project/library version is not a snapshot version, and it is greater than the
# latest release in GitHub, then it creates a draft PR for the new library version.
# This workflow always compares against the releases in amzn/ion-java, but will create
# a draft release in a forked repository if the workflow is triggered in a fork.
# See limitations at:
# https://github.com/amzn/ion-java/blob/master/.github/actions/inspect-version/action.yml
#
# This workflow is almost a reusable workflow that can be used by any of our repos that
# use semantic versioned releases. In order to make it reusable, we need to move it to
# a separate repo, update the workflow trigger ('on') to be 'workflow_call', and define
# inputs for any context that needs to be passed in. Any repo that uses this must either
# pass in the library version as a workflow argument, or it will need to have the
# `project.version` file. Also, there are some references to the 'master' branch that
# will need to be factored out (since some of our repos use 'main' as the default branch).
# Finally, there are references to "amzn/ion-java" should come from an input variable
# or be retrieved from the GitHub Actions context.
# See https://docs.github.com/en/actions/using-workflows/reusing-workflows
#
# This could also be bundled into a composite custom action instead of a workflow.
# See https://docs.github.com/en/actions/creating-actions/creating-a-composite-action

name: Prepare Release
on:
# We have a branch protection rule for master, so all commits to master require
# an approved PR. That means this workflow trigger is effectively equivalent to
# "on: PR that is merged into master"
push:
branches:
- 'master'
paths:
- 'project.version'
# Allow it to be manually triggered if necessary
workflow_dispatch:

jobs:
check-version:
name: Check Project Version
runs-on: ubuntu-latest
outputs:
should_create_draft: ${{ steps.inspect.outputs.is_valid_to_release }}
steps:
- uses: actions/checkout@v3
- name: Get project version
run: |
echo "PROJECT_VERSION=$(<project.version)" >> $GITHUB_ENV
- uses: ./.github/actions/inspect-version
id: inspect
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo: amzn/ion-java
project_version: ${{ env.PROJECT_VERSION }}
- run: |
echo "Result: ${{ toJSON(steps.inspect.outputs) }}"
test:
runs-on: ubuntu-latest
needs: check-version
steps:
- run: |
echo "check-version outputs: ${{ toJSON(needs.check-version.outputs) }}"
echo "Should run = ${{ needs.check-version.outputs.should_create_draft }}"
echo "Should run = ${{ needs.check-version.outputs.should_create_draft == 'true' }}"
create-draft:
name: Create Draft
runs-on: ubuntu-latest
needs: check-version
if: ${{ needs.check-version.outputs.should_create_draft == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Create a draft release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "valid to release: ${{ needs.check-version.steps.inspect.outputs.is_valid_to_release }}"
RELEASE_TAG="v$(<project.version)"
# This intentionally creates the draft release in the current repo, which
# could be a fork, if this workflow was triggered in a fork.
gh release create "$RELEASE_TAG" --draft --generate-notes
Loading

0 comments on commit 39bac87

Please sign in to comment.