-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
137 lines (128 loc) · 5.12 KB
/
action.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
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
135
136
137
name: 'DuploCloud Finish Release'
description: 'Finishes a gitflow release'
author: 'DuploCloud, Inc.'
inputs:
github_token:
required: true
description: 'Github token to use for pushing the tag and deleting the release branch'
target_ref:
required: false
description: 'release target ref (pull request base ref - defaults to {{ github.base_ref }}, which is usually master)'
default: ''
source_ref:
required: false
description: 'release source ref (pull request head ref - defaults to {{ github.head_ref }})'
default: ''
develop_ref:
required: false
description: 'develop ref (defaults to develop)'
default: 'develop'
tag_prefix:
required: false
description: 'The tag prefix (defaults to "v")'
default: 'v'
delete_branch:
required: false
description: 'Whether or not to delete the release branch.'
default: 'true'
validate_merge:
required: false
description: 'Validates that the source_ref was already merged into the target_ref. Set this to "false" if you merge a squashed commit.'
default: 'true'
outputs:
release_tag:
description: release git tag (with version prefix)
value: "${{ steps.validate.outputs.release_tag }}"
release_branch:
description: release git branch
value: "${{ steps.validate.outputs.release_branch }}"
release_commit:
description: release git commit
value: "${{ steps.validate.outputs.release_commit }}"
source_ref:
description: release source ref (pull request head)
value: "${{ steps.validate.outputs.source_ref }}"
target_ref:
description: release target ref (pull request base)
value: "${{ steps.validate.outputs.target_ref }}"
runs:
using: 'composite'
steps:
# VALIDATION: This check validates that the release has already been merged into master.
# - It also creates an "output" identifying the release commit.
- id: validate
shell: bash
run: |
# Fail on errors, and strictly interpret shell code
set -eu
# Get the target ref.
[ -z "$TARGET_REF" ] && TARGET_REF="${{ github.base_ref }}"
[ -z "$TARGET_REF" ] && TARGET_REF="master"
# Get the source ref.
[ -z "$SOURCE_REF" ] && SOURCE_REF="${{ github.head_ref }}"
[ -z "$SOURCE_REF" ] && SOURCE_REF="$(git rev-parse --abbrev-ref HEAD)"
# Get the release commit
if [ "$VALIDATE_MERGE" = "true" ]
then git checkout "$SOURCE_REF"
else git checkout "$TARGET_REF"
fi
# Identity the release version and the target git commit
RELEASE_VERSION="${SOURCE_REF##*/}"
RELEASE_TAG="${{ inputs.tag_prefix }}$RELEASE_VERSION"
RELEASE_COMMIT="$(git rev-parse HEAD)"
# Validate that the release commit exists in the target ref
if [ "$VALIDATE_MERGE" = "true" ] && ! git merge-base --is-ancestor "$RELEASE_COMMIT" "$TARGET_REF"; then
echo "::error cannot finish the release: the release must already be merged into '$TARGET_REF' branch"
exit 1
fi
# Checkout the target ref again, and output the release ref, tag and commit
git checkout "$TARGET_REF"
echo "source_ref=$SOURCE_REF" >> $GITHUB_OUTPUT
echo "target_ref=$TARGET_REF" >> $GITHUB_OUTPUT
echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "release_commit=$RELEASE_COMMIT" >> $GITHUB_OUTPUT
env:
VALIDATE_MERGE: "${{ inputs.validate_merge }}"
SOURCE_REF: "${{ inputs.source_ref }}"
TARGET_REF: "${{ inputs.target_ref }}"
# PUSH RELEASE TO GIT
- id: tag-release
shell: bash
run: |
git tag "$RELEASE_TAG"
env:
RELEASE_TAG: "${{ steps.validate.outputs.release_tag }}"
- name: Push tag
uses: ad-m/[email protected]
with:
github_token: ${{ inputs.github_token }}
branch: ${{ steps.validate.outputs.target_ref }}
tags: true
# START NEXT DEVELOP ITERATION:
# - Checkout develop.
# - Merge master back into develop.
# - Push develop.
- id: checkout-develop
uses: actions/checkout@v4
with:
ref: "${{ inputs.develop_ref }}"
fetch-depth: 0 # Workaround to allow merging from origin/master
persist-credentials: false # Needed so we can push with different credentials.
# NOTE: Pushing with different credentials allows admins to push protected branches.
# NOTE: Pushing with different credentials allow workflows to trigger from the push.
- id: merge-develop
shell: bash
run: |
git merge origin/${{ steps.validate.outputs.target_ref }} --no-edit
- uses: ad-m/[email protected]
with:
github_token: ${{ inputs.github_token }}
branch: develop
tags: true
# CLEAN UP RELEASE BRANCH
if: ${{ inputs.delete_branch == 'true' }}
uses: maxkomarychev/octions/octions/git/[email protected]
with:
token: ${{ inputs.github_token }}
ref: "heads/${{ steps.validate.outputs.source_ref }}"