Skip to content

Commit df11e4b

Browse files
authored
feat: Add option to use craft config from merge target branch to prepare release (#34)
Add a new optional input to the Prepare Release Action: `craft_config_from_merge_target` If this option is set to `true`, the craft config for preparing the release and reading the targets from will be taken from the merge target branch (if specified) instead of from the default branch.
1 parent 7fefa3f commit df11e4b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

action.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ inputs:
2222
description: The path that Craft will run inside. Defaults to `.`
2323
required: true
2424
default: "."
25+
craft_config_from_merge_target:
26+
description: Use the craft config from the merge target branch. Defaults to the repository's default branch
27+
default: false
2528

2629
runs:
2730
using: "composite"
@@ -63,6 +66,12 @@ runs:
6366
craft_url=$(curl -s https://api.github.com/repos/getsentry/craft/releases/${{ inputs.craft_version }} | jq -r '.assets[].browser_download_url | select(endswith("/craft"))')
6467
sudo curl -sL -o /usr/local/bin/craft "$craft_url"
6568
sudo chmod +x /usr/local/bin/craft
69+
- name: Checkout merge target branch
70+
if: inputs.craft_config_from_merge_target == 'true' && inputs.merge_target
71+
shell: bash
72+
run: |
73+
git fetch origin ${{ inputs.merge_target }}
74+
git checkout ${{ inputs.merge_target }}
6675
- name: Craft Prepare
6776
id: craft
6877
shell: bash
@@ -73,6 +82,20 @@ runs:
7382
# Ensure we have origin/HEAD set
7483
git remote set-head origin --auto
7584
CRAFT_LOG_LEVEL=Debug craft prepare "${{ env.RELEASE_VERSION }}"
85+
- name: Checkout merge target branch
86+
# We need to check out the merge target branch again because at the end of `craft prepare`
87+
# craft checks out the default branch
88+
if: inputs.craft_config_from_merge_target == 'true' && inputs.merge_target
89+
shell: bash
90+
run: |
91+
git fetch origin ${{ inputs.merge_target }}
92+
git checkout ${{ inputs.merge_target }}
93+
- name: Read Craft Targets
94+
id: craft-targets
95+
shell: bash
96+
env:
97+
CRAFT_LOG_LEVEL: Warn
98+
run: |
7699
targets=$(craft targets | jq -r '.[]|" - [ ] \(.)"')
77100
78101
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
@@ -96,7 +119,7 @@ runs:
96119
else
97120
subdirectory='/${{ inputs.path }}';
98121
fi
99-
122+
100123
if [[ -n '${{ inputs.merge_target }}' ]]; then
101124
merge_target='${{ inputs.merge_target }}';
102125
else
@@ -115,9 +138,9 @@ runs:
115138
fi
116139
117140
body="Requested by: @$GITHUB_ACTOR
118-
141+
119142
Merge target: $merge_target
120-
143+
121144
Quick links:
122145
- [View changes](https://github.com/$GITHUB_REPOSITORY/compare/${{ steps.release-git-info.outputs.last }}...${{ steps.release-git-info.outputs.branch }})
123146
- [View check runs](https://github.com/$GITHUB_REPOSITORY/commit/${{ steps.release-git-info.outputs.sha }}/checks/)
@@ -127,7 +150,7 @@ runs:
127150
128151
### Targets
129152
130-
${{ steps.craft.outputs.targets }}
153+
${{ steps.craft-targets.outputs.targets }}
131154
132155
Targets marked with a checkbox have already been executed. Administrators can manually tick a checkbox to force craft to skip it.
133156
"

0 commit comments

Comments
 (0)