skip to Main Content

I’m seeking to optimize my release deployment process across various GitHub repositories, and I’ve learned about the powerful automation capabilities of GitHub Actions. With multiple repositories under my ownership, my goal is to automate the release deployment process to ensure consistency and minimize manual effort.

Is there a method to deploy releases to multiple repositories within a single workflow run?

Here is my current workflow:

name: Test Workflow

on:
  pull_request:
    branches:
      - master

jobs:
  flutter_test:
    name: Run flutter test and analyze
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v1
        with:
          java-version: "12.x"
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.3.0"
      - run: flutter pub get
      - run: flutter test

  build_appbundle:
    name: Build flutter(Android)
    needs: [flutter_test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v1
        with:
          java-version: "12.x"
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.3.0"
      - run: flutter build apk --debug --split-per-abi
      - name: Push APK to Releases
        uses: ncipollo/release-action@v1
        with:
          artifacts: "build/app/outputs/apk/debug/*"
          tag: v1.0.${{ github.run_number }}

Currently, this workflow releases on the same repository. However, I’m aiming to extend this to release on multiple repositories. Any guidance on achieving this would be greatly appreciated.

2

Answers


  1. Chosen as BEST ANSWER
    name: Release Text File to Different Repo
    
    on:
      push:
        branches: ["main"]
      pull_request:
        branches: ["main"]
    
    jobs:
      build_and_release:
        name: Build and Release Text File
        runs-on: ubuntu-latest
        steps:
          - name: Checkout code
            uses: actions/checkout@v3
    
          - name: Create Text File
            run: echo "Hello, this is a sample text file." > sample.txt
    
          - name: Upload Text File
            uses: actions/upload-artifact@v2
            with:
              name: release
              path: sample.txt
    
          - name: Create Release
            id: create_release
            uses: actions/create-release@v1
            with:
              tag_name: v1.0.${{ github.run_number }}
              release_name: Release v1.0.${{ github.run_number }}
              body: "Release Notes for v1.0.${{ github.run_number }}"
              draft: false
              prerelease: false
              owner: target-repo-owner  # Replace with the owner of the target repository
              repo: target-repo-name    # Replace with the name of the target repository
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 
    
          - name: Attach Text File to Release
            id: upload_release_asset
            uses: actions/upload-release-asset@v1
            with:
              upload_url: ${{ steps.create_release.outputs.upload_url }}
              asset_path: sample.txt
              asset_name: sample.txt
              asset_content_type: "text/plain"
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    

    actually i want to release to different repo but i am getting this error while doing this **

    Error: Resource not accessible by integration

    **


  2. Certainly, you can use GitHub Actions to deploy releases to multiple repositories within a single workflow run. To achieve this, you can create a matrix strategy in your workflow where each matrix entry corresponds to a different repository. Then, you can customize the deployment steps based on the current matrix entry.

    Here’s an example modification to your existing workflow:

    name: Multi-Repo Release Workflow

    on:
    pull_request:
    branches:
    – master

    jobs:
    release:
    name: Release to Multiple Repos
    runs-on: ubuntu-latest
    strategy:
    matrix:
    repo:
    – owner: username1
    name: repository1
    – owner: username2
    name: repository2
    # Add more repositories as needed

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3
        with:
          repository: ${{ matrix.repo.owner }}/${{ matrix.repo.name }}
    
      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.3.0"
    
      - name: Install Dependencies
        run: flutter pub get
    
      - name: Run Tests
        run: flutter test
    
      - name: Build and Deploy
        run: |
          flutter build apk --debug --split-per-abi
          # Add any other deployment steps specific to your release process
    
          # Example: Pushing APK to Releases
          echo "Uploading artifacts to releases..."
          gh release create v1.0.${{ github.run_number }} ./build/app/outputs/apk/debug/*
    

    In this example:

    The workflow uses a matrix strategy with different repositories defined under the repo variable.
    The actions/checkout step is configured to checkout the specific repository based on the matrix entry.
    The subsequent steps (setting up Flutter, installing dependencies, running tests, building, and deploying) are common across repositories and will be executed for each matrix entry.
    You can customize the deployment steps as needed for each repository within the "Build and Deploy" step.
    Remember to replace username1/repository1, username2/repository2, and other placeholders with the actual GitHub usernames and repository names for the repositories you want to include in the multi-repo deployment.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search