Increments Flipcash versioning on the 1st of the month #14
This file contains hidden or 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: Increments Flipcash versioning on the 1st of the month | |
on: | |
schedule: | |
- cron: '0 0 1 * *' | |
workflow_dispatch: | |
jobs: | |
update-version: | |
name: Update versioning for new month | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@master | |
with: | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token | |
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo | |
ref: code/cash | |
- name: Generate year and month | |
id: date | |
run: | | |
YEAR=$(date +"%Y") | |
MONTH=$(date +"%m" | sed 's/^0//') | |
echo "YEAR=$YEAR" >> $GITHUB_OUTPUT | |
echo "MONTH=$MONTH" >> $GITHUB_OUTPUT | |
- name: Verify Packaging.kt exists | |
run: | | |
if [ ! -f buildSrc/src/main/java/Packaging.kt ]; then | |
echo "Error: Packaging.kt not found" | |
exit 1 | |
fi | |
- name: Update versioning fields | |
run: | | |
# Update majorVersion | |
sed -i '/object Flipcash : Packaging(/,/)/ s/majorVersion = [0-9]\{4\}/majorVersion = ${{ steps.date.outputs.YEAR }}/' buildSrc/src/main/java/Packaging.kt | |
# Update minorVersion | |
sed -i '/object Flipcash : Packaging(/,/)/ s/minorVersion = [0-9]\{1,2\}/minorVersion = ${{ steps.date.outputs.MONTH }}/' buildSrc/src/main/java/Packaging.kt | |
# Update patchVersion | |
sed -i '/object Flipcash : Packaging(/,/)/ s/patchVersion = [0-9]\+/patchVersion = 1/' buildSrc/src/main/java/Packaging.kt | |
- name: Validate updated fields | |
run: | | |
if ! grep -A 10 'object Flipcash : Packaging(' buildSrc/src/main/java/Packaging.kt | grep -q "majorVersion = ${{ steps.date.outputs.YEAR }}"; then | |
echo "Error: Failed to update majorVersion to ${{ steps.date.outputs.YEAR }}" | |
exit 1 | |
fi | |
if ! grep -A 10 'object Flipcash : Packaging(' buildSrc/src/main/java/Packaging.kt | grep -q "minorVersion = ${{ steps.date.outputs.MONTH }}"; then | |
echo "Error: Failed to update minorVersion to ${{ steps.date.outputs.MONTH }}" | |
exit 1 | |
fi | |
if ! grep -A 10 'object Flipcash : Packaging(' buildSrc/src/main/java/Packaging.kt | grep -q "patchVersion = 1"; then | |
echo "Error: Failed to reset patchVersion to 1" | |
exit 1 | |
fi | |
- name: Check for changes | |
id: check-changes | |
run: | | |
if git diff --quiet buildSrc/src/main/java/Packaging.kt; then | |
echo "No changes to commit" | |
echo "changed=false" >> $GITHUB_OUTPUT | |
else | |
echo "Changes detected" | |
echo "changed=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit & Push changes | |
if: steps.check-changes.outputs.changed == 'true' | |
uses: actions-js/push@master | |
with: | |
message: "build: update Flipcash versioning to ${{ steps.date.outputs.YEAR }}.${{ steps.date.outputs.MONTH }}" | |
branch: "code/cash" | |
github_token: ${{ secrets.BOT_GITHUB_TOKEN }} |