-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (81 loc) · 3.6 KB
/
release.yaml
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
90
name: Publish Release
on:
push:
branches:
- main
- staging
jobs:
release:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
token: ${{ secrets.MY_PAT }}
fetch-depth: 0
- name: Get branch name
if: startsWith(github.ref, 'refs/heads')
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
id: get_branch
- name: Get previous tag from the repo
id: get_latest_tag
run: |
repo_branch=${{ steps.get_branch.outputs.branch }}
branch_name="$repo_branch"
echo "branch_name=$(echo $branch_name)" >> $GITHUB_OUTPUT
tag=$(git tag)
git tag | grep $branch_name;
tag=$(git tag | grep "\<$branch_name\>" | sort -V | grep 'v[0-9].*' | tail -1)
echo $tag
echo "tag=$(git tag | grep "\<$branch_name\>" | sort -V | grep 'v[0-9].*' | tail -1)" >> $GITHUB_OUTPUT
if echo $tag | grep "999"; then
echo "command=$(echo 'm')" >> $GITHUB_OUTPUT
else
echo "command=$(echo 'p')" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Get new tag by doing semver version bump
id: bump_tag
run: |
git config --global http.postBuffer 1048576000
chmod +x ./scripts/version-upgrade.sh
bumped_tag=$(./scripts/version-upgrade.sh -${{ steps.get_latest_tag.outputs.command }} ${{ steps.get_latest_tag.outputs.tag }})
echo "new_tag=$(echo $bumped_tag)" >> $GITHUB_OUTPUT
- name: Get commit id
run: echo "version=$(echo `git ls-remote https://${{ secrets.MY_PAT }}@github.com/ujala-singh/github-repository-dispatch-receiver.git ${{ steps.get_branch.outputs.branch }} | awk '{ print $1}' | cut -c1-7`)" >> $GITHUB_OUTPUT
id: get_version
- name: Create Release on the repo
id: create_release
uses: ncipollo/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.MY_PAT }}
with:
tag: ${{ steps.bump_tag.outputs.new_tag }}-${{ steps.get_latest_tag.outputs.branch_name }}
name: ${{ github.event.repository.name }}
body: |
${{ github.event.head_commit.message }}
Commit id - ${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
owner: ujala-singh
repo: github-repository-dispatch-receiver
- name: Get SHA of the branch
id: get_sha
run: |
branch_name=${{ steps.get_branch.outputs.branch }}
sha=$(git rev-parse "refs/heads/$branch_name")
echo "GIT_SHA: $sha"
echo "sha=${sha}" >> $GITHUB_OUTPUT
- name: Update Tags
id: update_tags
run: |
#tag existing base tag
git tag -f ${{ steps.get_latest_tag.outputs.branch_name }}-base ${{ steps.get_sha.outputs.sha }}
#reset base tag
git push origin :refs/tags/${{ steps.get_latest_tag.outputs.branch_name }}-base
#push new commit with existing base tag
git push origin ${{ steps.get_latest_tag.outputs.branch_name }}-base
#tag and push versioned tag
git push origin :refs/tags/${{ steps.bump_tag.outputs.new_tag }}-${{ steps.get_latest_tag.outputs.branch_name }}
git tag -f ${{ steps.bump_tag.outputs.new_tag }}-${{ steps.get_latest_tag.outputs.branch_name }} ${{ steps.get_sha.outputs.sha }}
git push origin ${{ steps.bump_tag.outputs.new_tag }}-${{ steps.get_latest_tag.outputs.branch_name }}