[pre-commit.ci] pre-commit autoupdate #210
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
# Copyright 2021 Agnostiq Inc. | |
# | |
# This file is part of Covalent. | |
# | |
# Licensed under the Apache License 2.0 (the "License"). A copy of the | |
# License may be obtained with this software package or at | |
# | |
# https://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Use of this file is prohibited except in compliance with the License. | |
# 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: version | |
on: pull_request | |
jobs: | |
version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out head | |
uses: actions/checkout@v1 | |
with: | |
fetch-depth: 0 | |
- name: Check git history | |
run: | | |
if git merge-base --is-ancestor $GITHUB_SHA origin/develop; then | |
echo "DEVELOP_COMMIT_HISTORY=$GITHUB_SHA" >> $GITHUB_ENV | |
fi | |
- name: Check for version change | |
id: changed-version-file | |
uses: tj-actions/[email protected] | |
with: | |
files: | | |
VERSION | |
- name: Fail if version changed | |
if: ${{ steps.changed-version-file.outputs.any_changed == 'true' && github.sha != env.DEVELOP_COMMIT_HISTORY }} | |
run: | | |
echo "Version changes are prohibited in pull requests." | |
exit 10 | |
- name: Read head version | |
if: ${{ github.sha != env.DEVELOP_COMMIT_HISTORY }} | |
run: | | |
HEAD_VERSION="$(cat ./VERSION)" | |
echo "HEAD_VERSION=$HEAD_VERSION" >> $GITHUB_ENV | |
- name: Validate changelog entry | |
if: ${{ github.sha != env.DEVELOP_COMMIT_HISTORY }} | |
run: | | |
git diff --name-only origin/develop | grep CHANGELOG | |
unreleased_header_line=8 | |
if [[ $(sed "${unreleased_header_line}q;d" CHANGELOG.md) != "## [UNRELEASED]" ]] ; then | |
echo 'Removing the [UNRELEASED] header is prohibited in pull requests.' | |
exit 4 | |
fi | |
latest_release=$(sed -n "/\[[0-9]\+\.[0-9]\+\.[0-9]\+\]/=" CHANGELOG.md | head -n 1) | |
IFS='[]' read -ra changelog_version <<< $(sed "${latest_release}q;d" CHANGELOG.md) | |
if [[ "${changelog_version[1]}" != $HEAD_VERSION ]] ; then | |
echo 'The most recent CHANGELOG release does not match the VERSION'. | |
exit 3 | |
fi | |
#Check that the lines in the diff are between unreleased_header_line and latest_release | |
IFS='@-+,' read -ra LINES <<< "$(git diff develop -- CHANGELOG.md | sed '5q;d')" | |
start_head="$(( LINES[5] + 3 ))" | |
lines_head="$(( LINES[6] - 6 ))" | |
if [[ $start_head -lt $unreleased_header_line ]] || | |
[[ $((start_head + lines_head)) -gt $latest_release ]] ; then | |
echo 'Changes outside the UNRELEASED block are prohibited in pull requests.' | |
exit 6 | |
fi |