-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
92 lines (92 loc) · 4.03 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
name: SemVer Tag from PR
description: Easily version your commits using PR labels
branding:
icon: tag
color: blue
# Note: whenever an input is added/deleted, the runs.steps.env section needs to be updated as well!
inputs:
trunk:
description: trunk of the repository
required: true
default: main
label_major:
description: label override for major changes
required: true
default: merge-major
label_minor:
description: label override for minor changes
required: true
default: merge-minor
label_patch:
description: label override for patch changes
required: true
default: merge-patch
label_none:
description: label override for none changes
required: true
default: merge-none
repo_token:
description: gh token with permissions contents.write and pull-requests.read
required: true
repo_ssh_key:
description: ssh-key to use for pushing tags, base64 encoded. Only needed when you want to trigger additional actions after the tag push. For detailed explanation see Readme
required: true
repo_storage_path_overwrite:
description: path where the repository is cloned. Defaults to GITHUB_WORKSPACE
required: false
should_set_tag:
description: whether tag should be added to the cloned repo inside gh actions
required: true
default: "true"
should_push_tag:
description: whether tag should be pushed to the original repo
required: true
default: "true"
outputs:
old-tag:
description: the old tag before applying the semVer-bump
new-tag:
description: the new tag after applying the semVer-bump
# unfortunately I could not find a good way to ensure that the GIT_REF of the action
# always matches the image (e.g. using @v1.1.0 would automatically use v1.1.0 image and so on)
# Things tried:
# - use ${{ github.action_ref }} directly inside runs.image -> context 'github' is not available in this section
# - templating the version using the release action -> unfortunately action cannot push to protected branch
# - runs.image=Dockerfile -> the image will be rebuilt every time the action is being run, which adds roughly a minute in execution time
#
# => while the current solution is far from perfect and requires a bit more care when developing, it saves roughly
# one minute over the Dockerfile solution, which I find is worth it
runs:
using: composite
steps:
- name: run semver-tag-on-merge action
shell: bash
env:
VERSION: ${{ github.action_ref }}
WORKSPACE: ${{ github.workspace }}
INPUT_TRUNK: ${{ inputs.trunk }}
INPUT_LABEL_MAJOR: ${{ inputs.label_major }}
INPUT_LABEL_MINOR: ${{ inputs.label_minor }}
INPUT_LABEL_PATCH: ${{ inputs.label_patch }}
INPUT_LABEL_NONE: ${{ inputs.label_none }}
INPUT_REPO_TOKEN: ${{ inputs.repo_token }}
INPUT_REPO_SSH_KEY: ${{ inputs.repo_ssh_key }}
INPUT_REPO_STORAGE_PATH_OVERWRITE: ${{ inputs.repo_storage_path_overwrite }}
INPUT_SHOULD_SET_TAG: ${{ inputs.should_set_tag }}
INPUT_SHOULD_PUSH_TAG: ${{ inputs.should_push_tag }}
# we need to base64 encode the SSH_KEY due to https://github.com/moby/moby/issues/12997
# TODO (hack): for now I could not find a better way than manually creating the known_hosts entry for github.com
run: |
mkdir -p /home/runner/work/_temp/_github_home && \
ssh-keyscan -t ecdsa github.com > /home/runner/work/_temp/_github_home/known_hosts && \
export SSH_KNOWN_HOSTS="/github/home/known_hosts" && \
export INPUT_REPO_SSH_KEY=$(echo "$INPUT_REPO_SSH_KEY" | base64 -w 0) && \
docker run \
--workdir /github/workspace \
-v "${WORKSPACE}":"${WORKSPACE}" \
-v "/var/run/docker.sock":"/var/run/docker.sock" \
-v "/home/runner/work/_temp/_github_home":"/github/home" \
-v "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
-v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" \
--env-file <(env) \
ghcr.io/simontheleg/semver-tag-from-pr-action:${VERSION}