diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 1d6c9f97e..60759225a 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -1,22 +1,69 @@ -name: Release +name: Update Version on: push: branches: - main +# Add permissions configuration +permissions: + contents: write + pull-requests: write + jobs: - release: + version-bump: runs-on: ubuntu-latest + + # Add condition to skip if last commit was a release + if: "!startsWith(github.event.head_commit.message, 'chore(release)')" steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Run Release Please - uses: googleapis/release-please-action@v4 + # Step 1: Check out the repository + - name: Checkout Code + uses: actions/checkout@v4 with: - release-type: simple - path: . + fetch-depth: 0 # Fetch all history token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} - skip-github-release: true \ No newline at end of file + + # Step 2: Determine Version + - name: Determine Version + id: get_version + run: | + if [ ! -f "version.txt" ]; then + echo "0.0.1" > version.txt + fi + + CURRENT_VERSION=$(cat version.txt) + echo "Current Version: $CURRENT_VERSION" + + # Split version into components + IFS='.' read -r -a version_parts <<< "$CURRENT_VERSION" + MAJOR="${version_parts[0]}" + MINOR="${version_parts[1]}" + PATCH="${version_parts[2]}" + + # Increment patch version + NEW_PATCH=$((PATCH + 1)) + NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" + + echo "New Version: $NEW_VERSION" + + # Export versions for later steps + echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + + # Step 3: Update version.txt if version changes + - name: Update version.txt + if: env.CURRENT_VERSION != env.NEW_VERSION + run: | + echo "$NEW_VERSION" > version.txt + + # Step 4: Commit and Push Changes + - name: Commit and Push Changes + if: env.CURRENT_VERSION != env.NEW_VERSION + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add version.txt + git commit -m "chore(release): update version to $NEW_VERSION" + git push "https://${{ github.actor }}:${{ secrets.MY_RELEASE_PLEASE_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:main \ No newline at end of file diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 000000000..455bba3ef --- /dev/null +++ b/.github/workflows/update-version.yml @@ -0,0 +1,48 @@ +name: Update Version + +on: + push: + branches: + - main + +jobs: + version: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + + - name: Get previous version + id: previous_version + run: | + VERSION=$(grep "buster=" version.txt | cut -d'=' -f2) + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Conventional Commit Check and Version Bump + id: version_bump + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + default_bump: false + dry_run: true + tag_prefix: "" + + - name: Update version.txt + if: steps.version_bump.outputs.new_version != steps.previous_version.outputs.version + run: | + NEW_VERSION="${{ steps.version_bump.outputs.new_version }}" + sed -i "s/buster=.*/buster=$NEW_VERSION/" version.txt + + - name: Commit and push if changed + if: steps.version_bump.outputs.new_version != steps.previous_version.outputs.version + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add version.txt + git commit -m "chore: bump version to ${{ steps.version_bump.outputs.new_version }}" + git push + diff --git a/.gitignore b/.gitignore index b79670cf7..1b162d40c 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ Cargo.lock # Node.js dependencies node_modules/ + +.secrets \ No newline at end of file diff --git a/.release-please-config.json b/.release-please-config.json new file mode 100644 index 000000000..b7d7be878 --- /dev/null +++ b/.release-please-config.json @@ -0,0 +1,10 @@ +{ + "packages": { + ".": { + "release-type": "simple", + "changelog-path": "CHANGELOG.md", + "prerelease": true + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/README.md b/README.md index fccd5c4fc..352ae38ef 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@
diff --git a/version.txt b/version.txt index e69de29bb..bbdeab622 100644 --- a/version.txt +++ b/version.txt @@ -0,0 +1 @@ +0.0.5