-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (85 loc) · 3.37 KB
/
Hog-main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright 2018-2025 The University of Birmingham
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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: Hog-main
on:
workflow_call:
secrets:
HOG_PUSH_TOKEN:
required: true
HOG_EMAIL:
required: true
HOG_USER:
required: true
env:
HOG_PUSH_TOKEN: ${{ secrets.HOG_PUSH_TOKEN }}
HOG_USER: ${{ secrets.HOG_USER }}
HOG_EMAIL: ${{ secrets.HOG_EMAIL }}
jobs:
tag_official_version:
runs-on: ubuntu-latest
container: gitlab-registry.cern.ch/hog/hog-docker:master
steps:
- uses: actions/checkout@v4
name: Checkout Repository
with:
fetch-depth: 0
token: ${{secrets.HOG_PUSH_TOKEN}}
submodules: 'true'
- name: tag_official_version
shell: bash
run: |
git config --system --add safe.directory $(pwd)
git config --global user.email "$HOG_EMAIL"
git config --global user.name "$HOG_USER"
git fetch
git checkout $GITHUB_HEAD_REF
git pull
commit_message=$(git show --pretty=format:"%B" --no-patch)
if [[ $commit_message == "Merge pull request"* ]]; then
echo "Removing merge commit..."
echo "Current commit is $(git rev-parse HEAD)"
echo "Reverting to $(git log -n 1 --skip 1 --pretty=format:"%H")"
previous_commit=$(git log -n 1 --skip 1 --pretty=format:"%H")
git reset --hard $previous_commit
git push --force
exit 0
fi
git fetch origin refs/notes/*:refs/notes/*
note=(`git notes show`) || {
echo "No note found, probably you pushed to a branch that should protected (e.g. master, develop)";
exit 1;
}
new_tag=${note[2]}
if [ -z "$new_tag" ]; then
echo "It was impossible to get the tag number from the git note of this commit. Check that your repository settigns allows only merge commis, and that the merge_and_tag job in your Merge pipeline succeded."
echo "More info here https://hog.readthedocs.io/en/latest/02-User-Manual/02-Hog-CI/02-GitHub-Actions/01-Setup-Actions.html#merge-commit-handling-on-github-com"
exit 1
fi
present_tag=(`git describe`)
if [ $present_tag != $new_tag ]; then
if [ "$(git tag --list ${new_tag}*)" != "" ]; then
latest_tag=(`git tag -l ${new_tag}* --sort=-v:refname --merged`);
if [[ $latest_tag =~ .*-(.*) ]]; then
nr="${BASH_REMATCH[1]}";
new_tag="$new_tag-$(($nr+1))";
else
new_tag="$new_tag-0";
fi;
fi;
git tag $new_tag -m "Official_version_${new_tag}"
git push --tags
else
echo "Tagging is not necessary because the present commit is already tagged as:\ $new_tag.";
fi;