Stop touching sources during build #303
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | |
name: CI Build | |
on: | |
pull_request_target: | |
branches: | |
- main | |
types: | |
- closed | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
force_snapshot_release: | |
description: 'Update the snapshot release on github' | |
required: false | |
type: boolean | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Check if a snapshot release should be made and set environment variable | |
run: echo "MAKE_SNAPSHOT_RELEASE=${{ inputs.force_snapshot_release || (github.event.pull_request.base.ref == 'main' && github.event.action == 'closed' && github.event.pull_request.merged == true) }}" >> $GITHUB_ENV | |
# configure git | |
- name: setup git config | |
run: | | |
git config user.name ${{ github.actor }} | |
git config user.email "<>" | |
- name: Fetch branches (unless PR was merged) | |
if: ${{ env.MAKE_SNAPSHOT_RELEASE == 'false' }} | |
run: | | |
# as we aren't building main, let's fetch it | |
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} | |
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then | |
# Fetch from contributor’s fork | |
git remote add fork ${{ github.event.pull_request.head.repo.clone_url }} | |
git fetch fork ${{ github.event.pull_request.head.ref }}:${{ github.head_ref }} | |
else | |
# Fetch from the same repo | |
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} | |
fi | |
- name: Fail if src/main has changes but CHANGELOG.md does not (unless PR was merged) | |
if: ${{ env.MAKE_SNAPSHOT_RELEASE == 'false' }} | |
run: | | |
set -e | |
CHANGED_FILES=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }}) | |
if echo "$CHANGED_FILES" | grep -q '^src/main' && ! echo "$CHANGED_FILES" | grep -q '^CHANGELOG.md$'; then | |
echo "Directory src/main changed without an update of CHANGELOG.md, this is not allowed. Please update CHANGELOG.md" | |
exit 1 | |
fi | |
# Read version changelog before anything else - if there is a formatting error | |
# in the changelog (which happens), we fail fast | |
# Do this even if we will not make the snapshot release, so the changelog is checked as part of a normal | |
# ci run. | |
- name: Check Changelog formatting | |
id: get-changelog | |
uses: superfaceai/release-changelog-action@v1 | |
with: | |
path-to-changelog: CHANGELOG.md | |
version: ${{ inputs.release_version }} | |
operation: read | |
- name: Build with Maven | |
run: mvn -Pzip install | |
# delete the snapshot release (the release action does not update the | |
# body, so we have to delete the whole thing) | |
- name: Delete Snapshot Release | |
if: ${{ env.MAKE_SNAPSHOT_RELEASE == 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh release delete snapshot --cleanup-tag --yes || echo "Error deleting snapshot release - continuing anyway" | |
- name: change tag 'snapshot' to current commit | |
if: ${{ env.MAKE_SNAPSHOT_RELEASE == 'true' }} | |
run: | | |
git tag -f snapshot | |
git push -f origin --tags | |
- name: Make Release Body | |
if: ${{ env.MAKE_SNAPSHOT_RELEASE == 'true' }} | |
run: | | |
cat src/build/snapshot-release/release-body-header.md > target/release-body.md | |
echo "# Changes" >> target/release-body.md | |
cat <<'EOF' >> target/release-body.md | |
${{ steps.get-changelog.outputs.changelog }} | |
EOF | |
cat src/build/snapshot-release/release-body-footer.md >> target/release-body.md | |
# Make github release | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
if: ${{ env.MAKE_SNAPSHOT_RELEASE == 'true' }} | |
with: | |
name: Latest snapshot release | |
tag_name: snapshot | |
body_path: target/release-body.md | |
files: target/qudt-public-repo-*.zip | |
prerelease: true |