Merge pull request #38 from emdgroup/fix_versioning #36
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: Dev - 🚧 build package | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| jobs: | |
| commit-check: | |
| name: Commit Checker | |
| outputs: | |
| success: ${{ steps.check.outputs.success }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check last commit | |
| id: check | |
| run: | | |
| LAST_COMMITTER=$(git log -1 --pretty=format:'%an') | |
| if [[ "$LAST_COMMITTER" == "GitHub Actions" ]]; then | |
| echo "Last commit was made by GitHub Actions. Exiting..." | |
| echo "::set-output name=success::false" | |
| else | |
| echo "Last commit was made by a user. Executing..." | |
| echo "::set-output name=success::true" | |
| fi | |
| version: | |
| name: Version & Build | |
| needs: commit-check | |
| if: needs.commit-check.outputs.success == 'true' | |
| runs-on: macos-latest | |
| environment: release | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.get_new_version.outputs.result}} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{secrets.ELEVATED_TOKEN}} | |
| - name: 📇 Configure git | |
| run: | | |
| git fetch --prune --unshallow | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "gh-actions@merckgroup.com" | |
| shell: bash | |
| # Retrieve the new version | |
| - name: 🔂 Run standard-version | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const {execSync} = require('child_process'); | |
| execSync('npx standard-version --skip.tag --prerelease', {stdio: 'inherit'}); | |
| # Retrieve the new version | |
| - name: ⏎ Get new version | |
| uses: actions/github-script@v7 | |
| id: get_new_version | |
| with: | |
| result-encoding: string | |
| script: | | |
| const fs = require('fs'); | |
| const package = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| return package.version; | |
| - name: Print new version | |
| run: echo ${{ steps.get_new_version.outputs.result}} | |
| # Bump the pubspec.yaml file | |
| - name: ⬆️ Bump pubspec.yaml | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/update-pubspec@dev | |
| with: | |
| version: ${{ steps.get_new_version.outputs.result}} | |
| directory: . | |
| - name: 📝 Update version in readme | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/update-pubspec-readme-version@dev | |
| with: | |
| directory: . | |
| - name: Setup Dart | |
| uses: dart-lang/setup-dart@v1 | |
| - name: Prepare Flutter | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/prepare-flutter@dev | |
| with: | |
| directory: "." | |
| - name: Validate Flutter | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/validate-flutter@dev | |
| with: | |
| directory: "." | |
| is_package: true | |
| - name: Check licenses | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/check-dart-licenses@dev | |
| with: | |
| directory: "." | |
| matrix-generation: | |
| name: Generate Compatibility Matrix | |
| needs: version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.generate-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Fetch firmware versions | |
| uses: ./.github/actions/fetch-firmware-versions | |
| id: fetch-firmware-versions | |
| with: | |
| token: ${{secrets.ELEVATED_TOKEN}} | |
| - name: Generate compatibility matrix | |
| id: generate-matrix | |
| run: | | |
| # Parse the JSON arrays and create a matrix | |
| firmware_versions=$(echo '${{ steps.fetch-firmware-versions.outputs.versions }}' | jq -r '.[]') | |
| sdk_versions='${{ needs.version.outputs.version }}' | |
| echo "Latest 3 major.minor firmware versions:" | |
| echo "$firmware_versions" | |
| echo "" | |
| echo "Current SDK version:" | |
| echo "$sdk_versions" | |
| echo "" | |
| # Create matrix combinations using current SDK version with latest 3 firmware versions | |
| matrix_combinations="[]" | |
| count=0 | |
| while IFS= read -r firmware; do | |
| # For each firmware version, use the current SDK version | |
| combination=$(jq -n --arg fw "$firmware" --arg sdk "$sdk_versions" '{firmware: $fw, sdk: $sdk}') | |
| # Add to matrix array | |
| matrix_combinations=$(echo "$matrix_combinations" | jq --argjson combo "$combination" '. += [$combo]') | |
| count=$((count + 1)) | |
| done <<< "$firmware_versions" | |
| # Validate JSON before output | |
| if echo "$matrix_combinations" | jq empty 2>/dev/null; then | |
| # Use jq to compact the JSON for GitHub Actions output | |
| compact_matrix=$(echo "$matrix_combinations" | jq -c .) | |
| echo "matrix=$compact_matrix" >> $GITHUB_OUTPUT | |
| echo "Generated matrix with $count combinations (latest 3 firmware × current SDK version)" | |
| echo "Matrix preview:" | |
| echo "$matrix_combinations" | jq '.[0:3]' # Show first 3 combinations | |
| else | |
| echo "Error: Invalid JSON generated" | |
| echo "Generated content:" | |
| echo "$matrix_combinations" | |
| exit 1 | |
| fi | |
| compatibility-tests: | |
| name: Compatibility Tests | |
| needs: matrix-generation | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(needs.matrix-generation.outputs.matrix) }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Test compatibility | |
| uses: ./.github/actions/test-compatibility | |
| with: | |
| token: ${{secrets.ELEVATED_TOKEN}} | |
| firmware_version: ${{ matrix.firmware }} | |
| sdk_version: ${{ matrix.sdk }} | |
| generate-compatibility-matrix: | |
| name: Generate Compatibility Matrix | |
| needs: [version, compatibility-tests] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Generate matrix | |
| uses: ./.github/actions/generate-matrix | |
| - name: Upload compatibility matrix artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: firmware-compatibility-matrix | |
| path: assets/firmware_compatibility.json | |
| release: | |
| name: Release Package | |
| needs: [version, generate-compatibility-matrix] | |
| runs-on: macos-latest | |
| environment: release | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{secrets.ELEVATED_TOKEN}} | |
| - name: Download compatibility matrix | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: firmware-compatibility-matrix | |
| path: assets/ | |
| # Bump the pubspec.yaml file | |
| - name: ⬆️ Bump pubspec.yaml | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/update-pubspec@dev | |
| with: | |
| version: ${{ needs.version.outputs.version }} | |
| directory: . | |
| - name: 📝 Update version in readme | |
| uses: emdgroup/mtrust-urp/.github/shared_actions/update-pubspec-readme-version@dev | |
| with: | |
| directory: . | |
| - name: 📇 Configure git | |
| run: | | |
| git fetch --prune --unshallow | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "gh-actions@merckgroup.com" | |
| shell: bash | |
| # We first commit with proper message and add an empty commit to keep the files history clean | |
| - name: Update repo versions | |
| run: | | |
| git add . | |
| git commit -m "chore(release): ${{ needs.version.outputs.version }}" | |
| git commit --allow-empty -m "chore(release): ${{ needs.version.outputs.version }} [skip ci]" | |
| git push origin dev | |
| # For this part it is important to not push a commit with [skip ci] before the tag release | |
| - name: Push tag for pub.dev | |
| run: | | |
| git commit --allow-empty -m "chore(release): ${{ needs.version.outputs.version }}" | |
| git tag -a v${{ needs.version.outputs.version }} -m "Pub.dev version ${{ needs.version.outputs.version }}" | |
| git push origin v${{ needs.version.outputs.version }} |