ci: changie-trigger-release.yml #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: changie-trigger-release | ||
on: | ||
workflow_call: {} | ||
workflow_dispatch: {} | ||
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@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_ENV | ||
else | ||
echo "Branch exists. Skipping workflow." | ||
echo "BRANCH_ALREADY_EXISTS=true" >> $GITHUB_ENV | ||
fi | ||
- uses: aquaproj/aqua-installer@36dc5833b04eb63f06e3bb818aa6b7a6e6db99a9 # v2.1.2 | ||
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false' | ||
with: | ||
aqua_version: v2.10.1 | ||
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 | ||
if: steps.check_branch.outputs.BRANCH_ALREADY_EXISTS == 'false' | ||
run: | | ||
update_tags_for_package() { | ||
local Package=$1 | ||
local File="aqua.yaml" | ||
aqua generate -i "$1" | ||
local PackageRegex="^${Package}@.*" | ||
local tags=$(yq e ".packages[] | select(.name | test(\"$PackageRegex\")) | .tags[]" "$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\"])" "$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' | ||
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.BRANCH_ALREADY_EXISTS == 'false' | ||
run: | | ||
echo "Adding changelog files for commit..." | ||
git add .changes/* CHANGELOG*.md aqua.yaml | ||
- name: create-new | ||
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" |