forked from dell/common-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (119 loc) · 5.04 KB
/
release-creator.yaml
File metadata and controls
134 lines (119 loc) · 5.04 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright (c) 2025 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# 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
# This workflow is a reusable one for creating tag and release.
name: Tag and Release Creator
# Invocable as a reusable workflow
on:
workflow_call:
inputs:
version:
description: "Semantic version to release. Ex: major, minor, or patch"
required: true
type: string
jobs:
tag-and-release:
name: Create tag and release
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the full history including tags
ref: ${{ github.ref }} # Checkout the branch from which the workflow is triggered
# we will set the release version based on the user given input for older patch releases only ex: n-1, n-2
- name: Set release version
if: ${{ inputs.version != 'patch' || inputs.version != 'minor' || inputs.version != 'major' }}
run: |
echo "REL_VERSION=v${{ inputs.version }}" >> $GITHUB_ENV
# we will auto bump up the version if it is only patch, minor, or major else we will just use the user given input
- name: Get latest release
if: ${{ inputs.version == 'patch' || inputs.version == 'minor' || inputs.version == 'major' }}
run: |
latest_version=$(curl -s https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest | jq -r .tag_name)
echo "MY_VAR=${latest_version}" >> $GITHUB_ENV
echo "latest_version=${latest_version}"
- name: Increment version
if: ${{ inputs.version == 'patch' || inputs.version == 'minor' || inputs.version == 'major' }}
env:
MY_VAR: ${{ env.MY_VAR }}
run: |
current_version=$MY_VAR
current_version=(${current_version#v}) # remove 'v' prefix from $current_version"
IFS='.' read -r -a version_parts <<< "$current_version"
if "${{ inputs.version == 'major' }}"; then
# major version bump up
version_parts[0]=$(expr ${version_parts[0]} + 1)
new_version="${version_parts[0]}.0.0"
fi
if "${{ inputs.version == 'minor' }}"; then
# minor version bump up
version_parts[1]=$(expr ${version_parts[1]} + 1)
new_version="${version_parts[0]}.${version_parts[1]}.0"
fi
if "${{ inputs.version == 'patch' }}"; then
# patch version bump up
version_parts[2]=$(expr ${version_parts[2]} + 1)
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
fi
echo "New version to be released:v$new_version"
echo "REL_VERSION=v${new_version}" >> $GITHUB_ENV
# To import GPG key and configure git for signed commits (Annotated tags)
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_config_global: true
- name: Create new tag
env:
REL_VERSION: ${{ env.REL_VERSION }}
run: |
echo "new version to be released:$REL_VERSION"
git tag -s -a $REL_VERSION -m "Release $REL_VERSION"
git push origin $REL_VERSION
- name: Download binary
uses: actions/download-artifact@v4.3.0
# This is required to check if the binary exists and update its name to the release.
- run: |
FILE="./cert-csi-linux-amd64/cert-csi-linux-amd64"
if [ -d "repctl-linux-amd64" ]; then
FILE="./repctl-linux-amd64/repctl-linux-amd64"
fi
echo "File name: $FILE"
echo "FILE_NAME=$FILE" >> $GITHUB_ENV
shell: bash
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.REL_VERSION }}
name: Release ${{ env.REL_VERSION }}
draft: true
prerelease: false
generate_release_notes: true
make_latest: true
files: ${{ env.FILE_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REL_VERSION: ${{ env.REL_VERSION }}
FILE_NAME: ${{ env.FILE_NAME }}
- name: Create release branch
env:
REL_VERSION: ${{ env.REL_VERSION }}
run: |
branch_name="release/$REL_VERSION"
git fetch origin
if git ls-remote --heads origin $branch_name | grep $branch_name; then
echo "Branch name $branch_name already exists. Skipping branch creation."
git checkout $branch_name
else
git checkout -b $branch_name
git push origin $branch_name
fi