我正在尝试从
DEV
到 MAIN
分支的合并中获取提交消息,以便我可以插入到版本的正文中。
我尝试使用
get-commits
但没有成功。
这是我的意思是提交消息:
这是我的 YAML 文件:
name: "Build Android app"
on:
push:
branches: ['main', 'dev']
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 🗂️ Checkout repository
uses: actions/checkout@v2
- name: ☕ Instalando Java
uses: actions/setup-java@v3
with:
java-version: 17
distribution: adopt
cache: gradle
- name: 🔍 Validando Gradle
uses: gradle/wrapper-validation-action@v1
- name: 🖥️ Instalando Node
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'yarn'
- name: 📦 Instalando dependências
run: yarn install
- name: 🩹 Patch dependências
run: yarn patch-package
- name: 🔑 [DEV] Configura variáveis de ambiente de development
if: github.ref == 'refs/heads/dev'
run: |
echo "BASE_URL=${{ secrets.BASE_URL_DEV }}" >> .env.development
echo "BUILD_VARIANT=DEV" >> .env.development
echo "KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}" >> .env.development
echo "KEYSTORE_ALIAS=${{ secrets.KEYSTORE_ALIAS }}" >> .env.development
- name: 🔑 [PROD] Configura variáveis de ambiente de production
if: github.ref == 'refs/heads/main'
run: |
echo "BASE_URL=${{ secrets.BASE_URL_PROD }}" >> .env.production
echo "BUILD_VARIANT=PROD" >> .env.production
echo "KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}" >> .env.production
echo "KEYSTORE_ALIAS=${{ secrets.KEYSTORE_ALIAS }}" >> .env.production
- name: 🔓 Decodificar Keystore
run: |
echo $KEYSTORE_BASE_64 | base64 --decode > android/app/keystore.jks
env:
KEYSTORE_BASE_64: ${{ secrets.KEYSTORE_BASE_64 }}
- name: 🏗️ [DEV] Buildando aplicação development
if: github.ref == 'refs/heads/dev'
run: |
cd android
./gradlew assembleDevelopmentRelease
- name: 🏗️ [PROD] Buildando aplicação production
if: github.ref == 'refs/heads/main'
run: |
cd android
./gradlew assembleProductionRelease
- name: 📦 [PROD] Gerando AAB production
if: github.ref == 'refs/heads/main'
run: |
cd android
./gradlew bundleProductionRelease
- name: ⬆️ [DEV] Upload development APK artifact
if: github.ref == 'refs/heads/dev'
uses: actions/upload-artifact@v4
with:
name: android-development-apk
path: android/app/build/outputs/apk/development/release/app-development-release.apk
- name: ⬆️ [PROD] Upload production APK/AAB artifact
if: github.ref == 'refs/heads/main'
run: |
mkdir -p android-prod-bundle
cp android/app/build/outputs/apk/production/release/app-production-release.apk android-prod-bundle/
cp android/app/build/outputs/bundle/productionRelease/app-production-release.aab android-prod-bundle/
zip -r android-prod-bundle.zip android-prod-bundle/
- name: 📝 [PROD] Pegar versão do package.json
id: package-version
if: github.ref == 'refs/heads/main'
uses: martinbeentjes/[email protected]
- name: Pegar commits de Dev para Main
id: get-commits
uses: actions/github-script@v6
with:
script: |
const commits = await github.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'dev',
head: 'main'
});
const commitMessages = commits.data.commits.map(commit => `- ${commit.commit.message}`).join('\n');
return { commits: commitMessages };
- name: 🏷️ [PROD] Criar release se for branch main
id: create-release
if: github.ref == 'refs/heads/main'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package-version.outputs.current-version }}
release_name: ${{ steps.package-version.outputs.current-version }}
body: |
Changes in this release:
${{ steps.get-commits.outputs.commits }}
draft: false
prerelease: false
- name: ⬆️ [PROD] Upload APK asset para release
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./bundle.zip
asset_name: bundle.zip
asset_content_type: application/zip
对于您想要实现的目标,过去对我有用的一种方法是使用 GitHub API 来获取提交并抓取消息。
因此,我将更新您的 YAML 文件以捕获合并后的最新提交消息,如下所示:
name: "Build Android app"
on:
push:
branches: ['main', 'dev']
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 🗂️ Checkout repository
uses: actions/checkout@v2
- name: ☕ Instalando Java
uses: actions/setup-java@v3
with:
java-version: 17
distribution: adopt
cache: gradle
- name: 🔍 Validando Gradle
uses: gradle/wrapper-validation-action@v1
- name: 🖥️ Instalando Node
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'yarn'
- name: 📦 Instalando dependências
run: yarn install
- name: 🩹 Patch dependências
run: yarn patch-package
- name: Get commit message from merge
id: commit_message
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "commit_message=$COMMIT_MSG" >> $GITHUB_ENV
- name: Use commit message in release
run: |
echo "Creating release with commit message: ${{ env.commit_message }}"
#continue with your config
我添加的新步骤,
Get commit message from merge
运行git log
命令来提取最新的提交消息并将其存储在GitHub环境变量中(commit_message
)。
然后环境变量可用于其他步骤(例如创建版本或在工作流程的其他部分中使用它)。