From 921e1ca3a73480ae2fca0243d5c3d43b9e83a5ad Mon Sep 17 00:00:00 2001 From: Santiago Calle Gomez Date: Fri, 3 May 2024 10:50:13 -0500 Subject: [PATCH 1/2] fix(release): implementing semantic release --- .github/workflows/main.yml | 57 +++++++++++++++++++---------------- .github/workflows/release.yml | 57 +++++++++++++++++++++++++++++++++++ .nvmrc | 1 + .releaserc | 14 +++++++++ 4 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .nvmrc create mode 100644 .releaserc diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 372729f..037ac6f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,15 +12,42 @@ on: pull_request: branches: - main - release: - types: - - published jobs: build: + permissions: + contents: write + issues: write + pull-requests: write runs-on: ubuntu-latest steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - name: Generate a token + id: generate_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID_ADMIN_GITHUB }} + private_key: ${{ secrets.APP_PRIVATE_KEY_ADMIN_GITHUB }} + - uses: actions/checkout@v4 + with: + token: ${{ steps.generate_token.outputs.token }} + - name: Verify Conventional Commits + uses: amannn/action-semantic-pull-request@v5 + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Set up NodeJS + if: github.ref == 'refs/heads/main' # especificar rama principal + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + - name: Set up Semantic Release + if: github.ref == 'refs/heads/main' # especificar rama principal + run: npm -g install @semantic-release/git semantic-release@23.0.0 + - name: Semantic Release + if: github.ref == 'refs/heads/main' # especificar rama principal + run: npx semantic-release@23.0.0 + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} # debe crear un Personal Access Token - uses: actions/checkout@v3 - name: Set up JDK 17 uses: actions/setup-java@v3 @@ -39,25 +66,3 @@ jobs: -Dsonar.login=${{ secrets.SONAR_TOKEN }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - release: - if: github.event_name == 'release' - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Prepare gpg key - run: | - mkdir -p ~/.gradle/ - echo "${{secrets.SIGNING_KEY_FILE}}" | base64 -d > ~/.gradle/secring.gpg - - name: Publish Libraries - run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Psigning.keyId=${{ secrets.SIGNING_KEY_ID }} -Psigning.password=${{ secrets.SIGNING_KEY_PASSWORD }} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) - env: - ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.MAVEN_USERNAME }} - ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.MAVEN_PASSWORD }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ab0f9c9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: "release-actions" +on: + release: + types: [ released ] +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Generate a token + id: generate_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID_ADMIN_GITHUB }} + private_key: ${{ secrets.APP_PRIVATE_KEY_ADMIN_GITHUB }} + - uses: actions/checkout@v4 + with: + token: ${{ steps.generate_token.outputs.token }} + - name: Set env + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV + - name: Upgrade Gradle.properties + run: sed -i 's/version=.*/version=${{ env.RELEASE_VERSION }}/g' gradle.properties + - name: Generate Changelog + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + pullRequests: true + prWoLabels: true + issues: true + issuesWoLabels: true + stripGeneratorNotice: true + - name: Save version + uses: github-actions-x/commit@v2.9 + with: + github-token: ${{ steps.generate_token.outputs.token }} + push-branch: "main" # Set the correct branch + commit-message: 'docs(version): Update version to ${{ env.RELEASE_VERSION }}' # Change RELEASE_VERSION by your own or none + force-add: "true" + force-push: "true" + files: CHANGELOG.md README.md gradle.properties src/main/java/co/com/bancolombia/Constants.java # List of changed files + name: Release Bot + email: release-bot@bancolombia.com.co + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Prepare gpg key + run: | + mkdir -p ~/.gradle/ + echo "${{secrets.SIGNING_KEY_FILE}}" | base64 -d > ~/.gradle/secring.gpg + - name: Publish Libraries + run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Psigning.keyId=${{ secrets.SIGNING_KEY_ID }} -Psigning.password=${{ secrets.SIGNING_KEY_PASSWORD }} -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) + env: + ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.MAVEN_USERNAME }} + ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.MAVEN_PASSWORD }} \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..df93858 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v20.11.0 \ No newline at end of file diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..6a66cbd --- /dev/null +++ b/.releaserc @@ -0,0 +1,14 @@ +{ + "branches": ["master"], # especificar la rama principal + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + ["@semantic-release/git", + { + "assets": [ { "path": "build/**/*", "label": "Compiled files" }], # cambiar path por la ruta con el compilado de la app + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ], + "@semantic-release/github" + ] +} \ No newline at end of file From 3ef97d43fa3a140c29e22466f8cf683b1aff74f0 Mon Sep 17 00:00:00 2001 From: Santiago Calle Gomez Date: Fri, 3 May 2024 10:56:21 -0500 Subject: [PATCH 2/2] fix(release): implementing semantic release --- .releaserc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.releaserc b/.releaserc index 6a66cbd..d9ff352 100644 --- a/.releaserc +++ b/.releaserc @@ -1,11 +1,11 @@ { - "branches": ["master"], # especificar la rama principal + "branches": ["main"], "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", ["@semantic-release/git", { - "assets": [ { "path": "build/**/*", "label": "Compiled files" }], # cambiar path por la ruta con el compilado de la app + "assets": [ { "path": "build/**/*", "label": "Compiled files" }], "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" } ],