generated from AgnostiqHQ/covalent-executor-template
-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (70 loc) · 2.93 KB
/
version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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