This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
Automatic Release #8
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: Automatic Release | |
on: | |
schedule: | |
- cron: '0 0 * * 0' # Runs every Sunday at midnight UTC | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
update_version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
- name: Set up Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
- name: Update version in libs.versions.toml | |
id: update_version | |
run: | | |
VERSION_FILE="gradle/libs.versions.toml" | |
CURRENT_DATE=$(date +'%Y.%m.%d') | |
VERSION_CODE=$(grep 'version-code =' $VERSION_FILE | awk -F'=' '{print $2}' | tr -d ' "') | |
NEW_VERSION_CODE=$((VERSION_CODE + 1)) | |
sed -i "s/version-name = \".*\"/version-name = \"$CURRENT_DATE\"/" $VERSION_FILE | |
sed -i "s/version-code = \".*\"/version-code = \"$NEW_VERSION_CODE\"/" $VERSION_FILE | |
echo "NEW_VERSION_NAME=$CURRENT_DATE" >> $GITHUB_ENV | |
echo "NEW_VERSION_CODE=$NEW_VERSION_CODE" >> $GITHUB_ENV | |
- name: Create a new branch, commit and push changes | |
run: | | |
export NEW_BRANCH="auto-update-$(date +'%Y%m%d%H%M%S')" | |
git checkout -b $NEW_BRANCH | |
git add gradle/libs.versions.toml | |
git commit -m "Automatic release - v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" | |
git show --stat | |
git push origin $NEW_BRANCH | |
echo "NEW_BRANCH=$NEW_BRANCH" >> $GITHUB_ENV | |
- name: Debug - Show branches and commits | |
run: | | |
git branch -a | |
git log --oneline --graph --decorate | |
git diff HEAD^ HEAD | |
ls -l gradle/libs.versions.toml | |
- name: Create a Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Automatic release - v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" | |
base: "main" | |
branch: ${{ env.NEW_BRANCH }} | |
title: "Automatic release - v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" | |
body: "This PR updates the version-name to v${{ env.NEW_VERSION_NAME }} and increments the version-code to ${{ env.NEW_VERSION_CODE }}." | |
labels: auto-update |