-
Notifications
You must be signed in to change notification settings - Fork 1
154 lines (145 loc) · 6.95 KB
/
changie-trigger-release.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: changie-trigger-release
on:
workflow_call:
inputs:
additional_git_adds:
description: "Additional files to add to git, pass with single quotes and delimited with space `'file1.txt' 'folder/file2.txt'`"
required: false
type: string
workflow_dispatch:
inputs:
additional_git_adds:
description: "Additional files to add to git, pass with single quotes and delimited with space `'file1.txt' 'folder/file2.txt'`"
required: false
type: string
env:
BASE_BRANCH: 'main' # Default value for base branch
HEAD_BRANCH: 'chore/new-release-from-dependencies' # Default value for head branch
permissions:
contents: write
pull-requests: write
jobs:
dependency-release:
runs-on: ubuntu-latest
name: dependency-release
steps:
- name: checkout-repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0 # Ensures a full checkout
- name: configure-default-git-committer
run: |
git config user.name github-actions
git config user.email [email protected]
- name: check-branch-existence
id: check_branch
run: |
echo "Checking if '${{ env.HEAD_BRANCH }}' branch exists..."
if [[ -z "$(git ls-remote --heads origin "${{ env.HEAD_BRANCH }}")" ]]; then
echo "Branch does not exist. Continuing workflow."
echo "BRANCH_ALREADY_EXISTS=false" >> "$GITHUB_OUTPUT"
else
echo "Branch exists. Skipping workflow."
echo "BRANCH_ALREADY_EXISTS=true" >> "$GITHUB_OUTPUT"
fi
- uses: aquaproj/aqua-installer@6ce1f8848ec8e61f14d57bd5d7597057a6dd187c # v3.0.1
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
with:
aqua_version: v2.30.0
aqua_opts: '--only-link' # lazy install so we can start this way
policy_allow: true
env:
AQUA_LOG_LEVEL: debug
# - name: install-jq # install before aqua since aqua requirements will need jq already available
# uses: dcarbone/install-jq-action@8867ddb4788346d7c22b72ea2e2ffe4d514c7bcb # v2.1.0
- name: install-trunk
run: |
curl https://get.trunk.io -fsSL | bash -s -- -y
- name: ensure-requirements-are-in-aqua-config
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
run: |
update_tags_for_package() {
local Package="$1"
# doesn't seem to work when I provided qualified path, commenting out for reference/improvement later: local_file="$(aqua info | jq 'first(.config_files[].path)' | sed -e "s/(USER)/$(whoami)/g")"
local_file=$(find . -name "aqua.yaml" -print -quit)
echo "Path to the aqua.yaml file: ${local_file}"
echo "👉 aqua info output: $(aqua info)"
echo "👉 local_file for aqua detected as: ${local_file}"
aqua generate -i "${Package}"
local PackageRegex="^${Package}@.*"
local tags=$(yq e ".packages[] | select(.name | test(\"$PackageRegex\")) | .tags[]" "$local_file")
if [[ $tags =~ "release" ]]; then
echo "The package $Package already contains 'release' in 'tags'."
else
yq e -i "(.packages[] | select(.name | test(\"$PackageRegex\")) | .tags) |= (. // [] | . + [\"release\"])" "$local_file"
echo "Updated 'tags' of $Package to include 'release'."
fi
}
packages_to_update=("cli/cli" "miniscruff/changie" "mikefarah/yq")
for pkg in "${packages_to_update[@]}"; do
update_tags_for_package "$pkg"
done
aqua install --tags release
- name: update-aqua-checksum
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
run: |
git fetch
FILES_CHANGED=$(git diff --name-only "origin/${{ env.BASE_BRANCH }}" )
if [[ $FILES_CHANGED == *"aqua.yaml"* ]] || [[ $FILES_CHANGED == *"aqua-checksum.json"* ]] || [[ $FILES_CHANGED == *".aqua/aqua-checksum.json"* ]]; then
if [[ -f aqua-checksum.json ]] || [[ -f .aqua/aqua-checksum.json ]]; then
echo "updating aqua-checksum.json as this repo has one, and changes were detected in aqua"
echo "this might take a few minutes, be patient"
aqua update-checksum
else
echo "aqua-checksum.json not found, so no need to update this... skipping"
fi
else
echo "No changes in aqua.yaml or aqua-checksum.json files. Skipping update."
fi
- name: create-changelog-entry
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
timeout-minutes: 1 # in case missing kind, config, or asking for manual input (avoid), let's catch and fail quickly
run: |
echo "Creating changelog entry..."
LABEL=$(yq '.kinds[] | select(.key == "dependencies") | .key // "⬆️ Dependencies"' .changie.yaml)
LABEL=${LABEL:-⬆️ Dependencies}
echo "label format to use: $LABEL"
changie new --kind "${LABEL}" --body "Maintenance release due to updated dependencies."
changie batch auto
changie merge
- name: prepare-files-for-commit
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
run: |
echo "Adding changelog files for commit..."
git add '.changes/*' 'CHANGELOG*.md' '*aqua.yaml'
git add .
echo "this is added because unknown files have their version replaced and we should make sure these get included in the PR."
- name: add-additional-files
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false' && ${{ inputs.additional_git_adds != '' }}
run: |
echo "Adding additional files for commit..."
git add ${{ inputs.additional_git_adds }}
- name: trunk-fmt
run: |
trunk fmt
- name: create-new
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
run: |
git checkout -b ${{ env.HEAD_BRANCH }}
git commit -m "chore(deps): update changelogs"
git push -u origin ${{ env.HEAD_BRANCH }}
- name: create-pull-request
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Creating pull request..."
PR_OUTPUT=$(gh pr create --title "chore(deps): trigger a release based with changie updates" \
--body "Approval will trigger update." \
--base ${{ env.BASE_BRANCH }} \
--head ${{ env.HEAD_BRANCH }} \
--label dependencies)
PR_URL=$(echo "$PR_OUTPUT" | awk '/^https:\/\/github\.com/{print $1}')
PR_NUMBER=$(basename $PR_URL)
gh pr merge $PR_NUMBER --auto --delete-branch --squash
echo "configured autocomplete settings"