Release Creation #39
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: Release Creation | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Build the changelog | |
- name: Build Changelog | |
id: build_changelog | |
uses: mikepenz/release-changelog-builder-action@v4 | |
with: | |
configuration: ".github/configs/release-changelog-builder-action.json" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Change the update file | |
- name: Append changelog to file | |
id: check_append | |
run: | | |
echo "Checking and appending changelog to file if new" | |
changelog_content="${{ steps.build_changelog.outputs.changelog }}" | |
current_date=$(date -u +"%Y-%m-%d %H:%M:%S") | |
new_entry=$(cat <<EOF | |
# $current_date | |
$changelog_content | |
EOF | |
) | |
# Ensure the new entry ends with a newline | |
new_entry="${new_entry}\n" | |
# Ensure the existing updates file ends with a newline | |
if [ -s docs/updates.txt ] && [ "$(tail -c 1 docs/updates.txt)" != "" ]; then | |
echo "" >> docs/updates.txt | |
fi | |
# Extract the last changelog entry date from the existing file | |
last_entry_date=$(grep -m 1 '^# ' docs/updates.txt | head -n 1 | cut -d ' ' -f 2-) | |
# Check if the new entry is already present | |
if grep -q "$last_entry_date" <<< "$new_entry"; then | |
echo "No new changelog content to append." | |
echo "new_changes=false" >> $GITHUB_ENV | |
else | |
# Append the new entry to the updates file | |
echo -e "$new_entry" | cat - docs/updates.txt > temp | |
# Generate hashes of the original and new file content | |
original_hash=$(sha256sum docs/updates.txt | cut -d ' ' -f 1) | |
new_file_hash=$(sha256sum temp | cut -d ' ' -f 1) | |
# Compare the hashes and move the temporary file if they are different | |
if [ "$original_hash" != "$new_file_hash" ]; then | |
mv temp docs/updates.txt | |
echo "new_changes=true" >> $GITHUB_ENV | |
else | |
echo "No new changelog content to append." | |
echo "new_changes=false" >> $GITHUB_ENV | |
rm temp | |
fi | |
fi | |
- name: Commit changes | |
if: env.new_changes == 'true' | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add docs/updates.txt | |
git commit -m 'Update updates.txt' | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |