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
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Create GitHub prerelease after fast-forward check
on:
pull_request:
types:
- closed

jobs:
check-version-change:
if: github.event.pull_request.merged == true
name: check-version-change
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.check-version-change.outputs.result }}
steps:
- name: Checkout the current repository master branch
uses: actions/checkout@v3
with:
repository: amzn/ion-java
ref: master
fetch-depth: 2
path: ion-java-current

- name: Check whether the pull request contains version number bump
id: check-version-change
run: |
cd ion-java-current
versionNew=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
git reset --hard HEAD^
versionPrevious=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
if [[ $versionNew != $versionPrevious ]]; then echo "::set-output name=result::pass"; else echo "::set-output name=result::failed"; fi

prerelease:
name: prerelease
needs: check-version-change
if: ${{ needs.check-version-change.outputs.output1 == 'pass' }}
runs-on: ubuntu-latest
steps:
- name: Access to the incoming release
uses: actions/checkout@v3
with:
repository: amzn/ion-java
path: current_release

- name: Build ion-java
run: |
cd current_release
mvn clean install -DskipTests

- name: Get the parameters of executable jar
run: |
cd current_release/target
echo "path=$(readlink -f $(ls *.jar))" >> $GITHUB_ENV
echo "file_name=$(ls *.jar)" >> $GITHUB_ENV
cd .. && echo "version_number=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV

- name: Create new release
id: create_new_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.version_number }}
release_name: v${{ env.version_number }}
prerelease: true
Comment on lines +56 to +64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify in this workflow that no release for this version already exists? That would ensure that we don't accidentally create a new release without updating the version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify in this workflow that no release for this version already exists? That would ensure that we don't accidentally create a new release without updating the version.
This workflow will be triggered manually after the version bump PR merged, but I agree. It would be a good idea to add one step to check the version number change in case this workflow is triggered accidentally.


- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_new_release.outputs.upload_url }}
asset_path: ${{ env.path }}
asset_name: ${{ env.file_name }}
asset_content_type: application/zip
91 changes: 91 additions & 0 deletions .github/workflows/version-bump-and-fast-forward-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Version-bump-and-fast-forward-check
on: [pull_request]

jobs:
check-version-bump:
name: check-version-bump
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.check-version-change.outputs.result }}
steps:
- name: Switch to the branch of the pull request
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
path: ion-java-new

- name: Checkout the current repository master branch
uses: actions/checkout@v3
with:
repository: amzn/ion-java
ref: master
path: ion-java-current

- name: Check whether the pull request contains version number bump
id: check-version-change
run: |
cd /home/runner/work/ion-java/ion-java/ion-java-new
versionNew=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
commitID=$(git rev-parse HEAD)
cd /home/runner/work/ion-java/ion-java/ion-java-current
versionCurrent=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
if [[ $versionNew != $versionCurrent ]]; then echo "::set-output name=result::pass"; else echo "::set-output name=result::failed"; fi

fast-forward-check:
needs: check-version-bump
name: fast-forward-check
if: ${{ needs.check-version-bump.outputs.output1 == 'pass' }}
runs-on: ubuntu-latest
steps:
- name: Access to the last release
uses: oprypin/find-latest-tag@v1
id: check_last_release
with:
repository: amzn/ion-java
releases-only: true

- name: Checkout the last release
uses: actions/checkout@v3
with:
repository: amzn/ion-java
ref: ${{ steps.check_last_release.outputs.tag }}
path: last-release

- name: Get the commit id of the last release
run: |
cd last-release
echo "last_release_commit_id=$(git rev-parse HEAD)" >> $GITHUB_ENV

- name: Access to the incoming release
uses: actions/checkout@v3
with:
repository: amzn/ion-java
ref: ${{ github.event.pull_request.head.sha }}
path: ion-java-new

- name: Get the commit id of the incoming release
run: |
cd ion-java-new
echo "current_release_commit_id=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo $(git rev-parse HEAD)

- name: Check whether the incoming release is fast-forward compared to the last release
run: |
cd ion-java-new
if git merge-base --is-ancestor ${{env.last_release_commit_id}} ${{env.current_release_commit_id}}; then echo "Trigger github release"; else exit 1; fi

- name: comment
if: ${{ success() }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
This PR passes version bump check and fast-forward check, please double check the version number and merge this PR. After merging this PR, "Create gitHub prerelease after fast-forward check" workflow will be automatically triggered to create prerelease.

- name: comment
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
This PR is not fast-forward compared to the last release, please check.