-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (129 loc) · 5.22 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
---
# Assumptions:
# - no project used in changie (no monorepo supported yet)
# - no components used in changie.
# - Dependencency type: ⬆️ Dependencies mapped in .changie.yaml
name: changie-trigger-release
on:
workflow_call:
inputs:
base:
type: string
required: false
default: 'main'
description: 'Target for the pull request'
head:
type: string
required: false
default: 'chore/new-release-from-dependencies'
description: 'Head branch for the PR'
workflow_dispatch:
inputs:
base:
required: false
default: 'main'
description: 'Target for the pull request'
head:
required: false
default: 'chore/new-release-from-dependencies'
description: 'Head branch for the PR'
permissions:
contents: write
pull-requests: write
jobs:
dependency-release:
runs-on: ubuntu-latest
name: dependency-release
steps:
- name: checkout-repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensures a full checkout
- name: check-branch-existence
id: check_branch
run: |
echo "Checking if '${{ github.event.inputs.head }}' branch exists..."
if git ls-remote --heads origin ${{ github.event.inputs.head }}; then
echo "Branch exists. Skipping workflow."
echo "BRANCH_ALREADY_EXISTS=true >> $GITHUB_OUTPUT"
else
echo "Branch does not exist. Continuing workflow."
echo "BRANCH_ALREADY_EXISTS=false >> $GITHUB_OUTPUT"
fi
- uses: aquaproj/aqua-installer@36dc5833b04eb63f06e3bb818aa6b7a6e6db99a9 # v2.1.2
with:
aqua_version: v2.10.1
# working_directory:
aqua_opts: '--only-link' # lazy install so we can start this way
policy_allow: true
env:
AQUA_LOG_LEVEL: debug
- name: ensure-requirements-are-in-aqua-config
run: |
update_tags_for_package() {
local Package=$1
local File="aqua.yaml"
aqua generate -i "$1"
# Regex for partial match of the package name
local PackageRegex="^${Package}@.*"
# Retrieve the tags for the matched package
local tags=$(yq e ".packages[] | select(.name | test(\"$PackageRegex\")) | .tags[]" "$File")
# Check if 'release' is one of the tags
if [[ $tags =~ "release" ]]; then
echo "The package $Package already contains 'release' in 'tags'."
else
# Add 'release' to tags if it doesn't exist
yq e -i "(.packages[] | select(.name | test(\"$PackageRegex\")) | .tags) |= (. // [] | . + [\"release\"])" "$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
run: |
git fetch
FILES_CHANGED=$(git diff --name-only "origin/${{ github.event.inputs.base }}" )
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.conclusion == 'false'
run: |
echo "Creating changelog entry..."
changie new --kind "⬆️ Dependencies" --body "Maintenance release due to updated dependencies."
changie batch auto
changie merge
- name: prepare-files-for-commit
if: steps.check_branch.outputs.conclusion == 'false'
run: |
echo "Adding changelog files for commit..."
git add .changes/* CHANGELOG*.md aqua.yaml
- name: create-new-branch
if: steps.check_branch.outputs.conclusion == 'false'
run: |
echo "Creating new branch..."
git checkout -b ${{ github.event.inputs.head }}
git commit -m "chore(deps): update changelogs"
git push -u origin ${{ github.event.inputs.head }}
- name: create-pull-request
if: steps.check_branch.outputs.conclusion == 'false'
run: |
echo "Creating pull request..."
gh pr create --title "chore(deps): trigger a release based with changie updates" \
--body "Approval will trigger update." \
--base ${{ github.event.inputs.base }} \
--head ${{ github.event.inputs.head }} \
--label dependencies \
--squash \
--delete-branch-on-merge