diff --git a/.github/workflows/create-gitHub-prerelease-after-fast-forward-check.yml b/.github/workflows/create-gitHub-prerelease-after-fast-forward-check.yml new file mode 100644 index 0000000000..d28a958a74 --- /dev/null +++ b/.github/workflows/create-gitHub-prerelease-after-fast-forward-check.yml @@ -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 + + - 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 \ No newline at end of file diff --git a/.github/workflows/version-bump-and-fast-forward-check.yml b/.github/workflows/version-bump-and-fast-forward-check.yml new file mode 100644 index 0000000000..d355144565 --- /dev/null +++ b/.github/workflows/version-bump-and-fast-forward-check.yml @@ -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.