diff --git a/.github/workflows/.release-please-manifest-rc.json b/.github/workflows/.release-please-manifest-rc.json new file mode 100644 index 00000000..fea34540 --- /dev/null +++ b/.github/workflows/.release-please-manifest-rc.json @@ -0,0 +1,3 @@ +{ + ".": "1.0.0" +} \ No newline at end of file diff --git a/.github/workflows/create-changelog.yml b/.github/workflows/create-changelog.yml new file mode 100644 index 00000000..eed87f25 --- /dev/null +++ b/.github/workflows/create-changelog.yml @@ -0,0 +1,71 @@ +name: Create Changelog + +on: + push: + branches: + - release/* + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + check-skip: + runs-on: ubuntu-latest + outputs: + should_skip: ${{ steps.check.outputs.should_skip }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + + # Check if the commit is a release PR and skip the job + - name: Check if the commit is a release PR + id: check + run: | + COMMIT_MSG=$(git log -1 --pretty=%B) + if [[ $COMMIT_MSG == *"Merge pull request"* && $COMMIT_MSG == *"release-please--branches"* ]]; then + echo "should_skip=true" >> "$GITHUB_OUTPUT" + fi + + create-changelog: + runs-on: ubuntu-latest + needs: check-skip + if: needs.check-skip.outputs.should_skip != 'true' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Get the version from version.json file and store it in the output file + - name: Get version from version.json + id: retrieve_version + run: | + new_version=$(jq -r '.version' version.json) + if [ -z "$new_version" ]; then + echo "Error: version field is empty or not found in version.json!" + exit 1 + fi + echo "new_version=$new_version" >> "$GITHUB_OUTPUT" + + # Set release version for changelog + - name: Set release version for changelog + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git commit --allow-empty -m "chore: release ${{ steps.retrieve_version.outputs.new_version }}" -m "Release-As: ${{ steps.retrieve_version.outputs.new_version }}" + git push + + # Create release changelog + - name: Create release changelog + id: release + uses: googleapis/release-please-action@v4 + with: + token: ${{ secrets.RELEASE_PLEASE_TOKEN }} + target-branch: ${{ github.ref_name }} + config-file: .github/workflows/release-please-config.json + manifest-file: .github/workflows/.release-please-manifest-rc.json diff --git a/.github/workflows/release-please-config.json b/.github/workflows/release-please-config.json new file mode 100644 index 00000000..a867043b --- /dev/null +++ b/.github/workflows/release-please-config.json @@ -0,0 +1,57 @@ +{ + "plugins": ["node-workspace", "sentence-case"], + "always-update": true, + "skip-github-release": true, + "pull-request-header": "🤖: I have generated a release changelog", + "pull-request-footer": "This PR was automatically generated by 🤖.", + "include-component-in-tag": false, + "packages": { + ".": { + "release-type": "simple", + "changelog-sections": [ + { + "type": "feat", + "section": "Features", + "hidden": false, + "type-plural": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes", + "hidden": false, + "type-plural": "Bug Fixes" + }, + { + "type": "refactor", + "section": "Code Refactoring", + "hidden": false, + "type-plural": "Code Refactoring" + }, + { + "type": "test", + "section": "Tests", + "hidden": false, + "type-plural": "Tests" + }, + { + "type": "changed", + "section": "Changed", + "hidden": false, + "type-plural": "Changes" + }, + { + "type": "docs", + "section": "Documentation", + "hidden": false, + "type-plural": "Documentation" + }, + { + "type": "chore", + "section": "Miscellaneous", + "hidden": false, + "type-plural": "Chores" + } + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..d02cc74c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +name: Release + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + outputs: + new_version: ${{ steps.retrieve_version.outputs.new_version }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Get the version from version.json file and store it in the output file + - name: Get version from version.json + id: retrieve_version + run: | + new_version=$(jq -r '.version' version.json) + if [ -z "$new_version" ]; then + echo "Error: version field is empty or not found in version.json!" + exit 1 + fi + echo "new_version=$new_version" >> "$GITHUB_OUTPUT" + + # Create tag to the repository by using the version from the output file + - name: Create tag + id: create-tag + run: | + new_version=${{ steps.retrieve_version.outputs.new_version }} + + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git tag -a "$new_version" -m "Release version $new_version" + git push origin "$new_version" + + echo "new_tag=$new_version" >> "$GITHUB_OUTPUT" + + # Create GitHub release + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + new_version=${{ steps.retrieve_version.outputs.new_version }} + new_tag=${{ steps.create-tag.outputs.new_tag }} + + sed -n "/## \[$new_version\]/,/## \[/p" CHANGELOG.md | sed '$d' > release_notes.md + + gh release create "$new_tag" \ + --title "Release ${{ steps.retrieve_version.outputs.new_version }}" \ + --notes-file release_notes.md \ + --target ${{ github.ref_name }} \ No newline at end of file