如何从不同的存储库使用 github 工作流?

如何从不同的存储库使用 github 工作流?

这是我的工作流文件,与源代码位于同一个存储库中。

我的工作流文件与代码位于同一个存储库中,但我想将其保存在单独的存储库中并在此处使用。该怎么做?

# 64bit Product

name: CI_Product_Windows_NewInstall

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches:
      - "DCloud*"
      - "MasterLayer*"

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

concurrency: CI_Product_Windows

env:
  Version_Number: "99.009"
  build_architecture: "x64"
  Version: "12.5"
  #onedrivefolder: ${{ secrets.BUILDS_FOLDER }} 

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  build:
    # The type of runner that the job will run on
    runs-on: ProductBuild2
    outputs:
      output1: ${{ steps.build_number.outputs.buildNumber }}
      output2: ${{ steps.extract_branch.outputs.BRANCH_NAME }}
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # To fetch secrets from Keyvault
      - uses: azure/login@v1
        name: Azure Login
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      - uses: Azure/get-keyvault-secrets@v1
        with:
          keyvault: ${{ secrets.KEYVAULT_NAME }}
          secrets: "MAIL-PASSWORD, DM-GROUP-MAIL, MICROSOFT-TEAMS-WEBHOOK-URI-Product, Product-DAILY-BUILDS-URL, Product-BUILDS-FOLDER"
        id: myGetSecretAction
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      # Runs a single command using the runners shell
      - name: git commit count calculate and set to environment variable
        run: |
          pwd
          echo "checking count"
          $count = git log --oneline | wc -l
          echo $count
          echo "git_commit_count=$count" >> $env:GITHUB_ENV
      - name: Print Build Number
        run: echo ${{ env.git_commit_count }}
      - name: export Build Number
        id: build_number
        run: echo "::set-output name=buildNumber::${{ env.git_commit_count }}"

      - name: Extract branch name
        if: github.event_name != 'pull_request'
        shell: bash
        run: echo "::set-output name=BRANCH_NAME::$(branchname=${GITHUB_REF#refs/heads/};echo ${branchname,,})"
        id: extract_branch
        env:
          ACTIONS_ALLOW_UNSECURE_COMMANDS: true
      - name: Setup Maven
        uses: stCarolas/[email protected]
        with:
          maven-version: 3.8.3
      - name: Set up JDK 16
        uses: actions/setup-java@v2
        with:
          java-version: '17'
          distribution: 'adopt'
          cache: maven
      - name: Check Java and Maven Version
        run: java --version;mvn --version;where java;where mvn;pwd;ls
      ###Should install below packages on the machine while creating the machine first time.
      ## install nodejs 16.16(LTS https://nodejs.org/dist/v16.16.0/node-v16.16.0-x64.msi)
      ## npm install yarn -g
      - name: Check ENV for Product2 node build
        working-directory: Product2
        run: |
          pwd
          node -v
          npm -v
          yarn -v
      - name: Build ProductAdmin node build
        working-directory: Productadmin
        run: |
          npm install --force
          npm run build
      - name: Build Product2 node build
        working-directory: Product2
        run: |
          yarn install
          yarn run eslint --fix src
          yarn build
      - name: Build Product Service
        run: mvn clean package --file pom.xml
        env:
          CI: false
      - name: Build Vault Service
        working-directory: VaultService
        run: mvn clean package --file pom.xml
        env:
          CI: false
      - name: Build Product Portal
        working-directory: ProductPortal
        run: pwd;mvn clean package --file pom.xml
        env:
          CI: false
      - name: Upload Logs
        if: success() || failure()
        uses: actions/upload-artifact@v3
        with:
          name: VS SLN FILES LOGS
          retention-days: 5
          path: |
            *.log
      - name: Send failure mail
        if: failure()
        uses: juanformoso/action-send-mail@1
        with:
          # SMTP server address
          server_address: smtp.sendgrid.net
          # SMTP server port
          server_port: 587
          # Authenticate as this user to SMTP server
          username: apikey
          # Authenticate with this password to SMTP server
          password: ${{ steps.myGetSecretAction.outputs.MAIL-PASSWORD }}
          # Subject of mail message
          subject: ${{ github.workflow }} - ${{ env.Version }} - ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }} GitHubWorkflow_Build:${{ github.run_number }}
          # Body of mail message (might be a filename prefixed with file:// to read from)
          body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }} with job url ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
          # Recipients mail addresses (separated with comma)
          to: ${{ steps.myGetSecretAction.outputs.DM-GROUP-MAIL }}
          # Email address of the sender
          from: [email protected]
          # Content-Type HTTP header (text/html or text/plain)
          content_type: text/html
          # Convert body from Markdown to HTML (set content_type input as text/html too)
          convert_markdown: true
      - name: Notify in Teams Channel for failure
        if: failure()
        shell: powershell
        run: |
          $body=@"
          {
              "@type": "MessageCard",
              "@context": "http://schema.org/extensions",
              "themeColor": "d73600",
              "summary": "Notification Summary",
              "sections": [{
                  "facts": [{
                      "name": "Workflow Name",
                      "value": "${env:GITHUB_WORKFLOW} - ${env:Version}"
                  },{
                      "name": "Execution branch",
                      "value": "${env:GITHUB_REF_NAME}"
                  }, {
                      "name": "Workflow Build Number",
                      "value": "${{ github.run_number }}"
                  }, {
                      "name": "Repository",
                      "value": "${{ github.repository }}"
                  }, {
                      "name": "Commit Message",
                      "value": "${{ github.event.head_commit.message }}"
                  }, {
                      "name": "Job name",
                      "value": "${{ github.job }}"
                  },
                  {
                      "name": "Job URL",
                      "value": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
                  },
                  {
                      "name": "Job status",
                      "value": "${{ job.status }}"
                  }],
                  "markdown": true
              }]
          }
          "@
          Invoke-RestMethod -Method post -ContentType 'Application/Json' -Body $body -Uri ${{ steps.myGetSecretAction.outputs.MICROSOFT-TEAMS-WEBHOOK-URI-Product }}
  # This workflow contains a single job called "build"
  createInstaller:
    # The type of runner that the job will run on
    runs-on: Installshield2023
    needs:
      - build
    env:
      git_commit_count: ${{needs.build.outputs.output1}}
      BRANCH_NAME: ${{needs.build.outputs.output2}}
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # To fetch secrets from Keyvault
      - uses: azure/login@v1
        name: Azure Login
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      - uses: Azure/get-keyvault-secrets@v1
        with:
          keyvault: ${{ secrets.KEYVAULT_NAME }}
          secrets: "MAIL-PASSWORD, DM-GROUP-MAIL, MICROSOFT-TEAMS-WEBHOOK-URI-Product, Product-DAILY-BUILDS-URL, Product-BUILDS-FOLDER"
        id: myGetSecretAction
      - name: Print build number
        run: echo ${{ env.git_commit_count }}
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Build ProductPortal ISM 64bit
        uses: ./installs_repo/workflows/buildism/
        with:
          ismfile: "C:\\actions-runner\\_work\\company-Product-MCL-NewUI\\company-Product-MCL-NewUI\\installs_repo\\Projectwise ISM files\\${{ env.Version }}_new\\company ProductPortal ${{ env.Version }}_64bit.ism"
          release_name: "SINGLE_EXE_IMAGE"
          setup_name: "company Product Portal ${{ env.Version }} (64-bit)_${{ env.git_commit_count }}.exe"
          #onedrivefolder: "${{ steps.myGetSecretAction.outputs.Product-BUILDS-FOLDER }}\\new_Product" 
      - uses: jfrog/setup-jfrog-cli@v2
        env:
          # JFrog platform url (for example: https://acme.jfrog.io)
          JF_URL: "https://company.jfrog.io"
          JF_USER: ${{ secrets.JFROG_USERNAME }}
          JF_PASSWORD: ${{ secrets.JFROG_PASSWORD }}
      - run: |
          jf rt ping
          echo $env:BRANCH_NAME
          echo ${{ github.run_number }}
          jf rt upload "company Product Portal ${{ env.Version }} (64-bit)_${{ env.git_commit_count }}.exe" companydm-datamodeler/Product/Product${{ env.Version }}/$env:BRANCH_NAME/${{ github.run_number }}/

      - name: Notify in Teams Channel
        shell: powershell
        run: |
          $body=@"
          {
              "@type": "MessageCard",
              "@context": "http://schema.org/extensions",
              "themeColor": "00d736",
              "summary": "Notification Summary",
              "sections": [{
                  "facts": [{
                      "name": "Repository",
                      "value": "${{ github.repository }}"
                  }, {
                      "name": "Workflow",
                      "value": "${env:GITHUB_WORKFLOW} ${env:Version}"
                  },{
                      "name": "GitHub Run Number",
                      "value": "${{ github.run_number }}"
                  },{
                      "name": "Branch",
                      "value": "${env:GITHUB_REF_NAME}"
                  },{
                      "name": "Commit Message",
                      "value": "${{ github.event.head_commit.message }}"
                  },
                  {
                      "name": "Job URL",
                      "value": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
                  },{
                      "name": "Commit Count",
                      "value": "${{ env.git_commit_count }}"
                  }, {
                      "name": "JFrog Link",
                      "value": "[company Product Portal ${{ env.Version }} (64-bit)_${{ env.git_commit_count }}.exe](https://company.jfrog.io/artifactory/companydm-datamodeler/Product/Product${{ env.Version }}/$env:BRANCH_NAME/${{ github.run_number }}/company%20Product%20Portal%20${{ env.Version }}%20(64-bit)_${{ env.git_commit_count }}.exe)"
                  },{
                      "name": "OneDrive link",
                      "value": "Click on [Daily Builds](${{ steps.myGetSecretAction.outputs.Product-DAILY-BUILDS-URL }})"
                  }],
                  "markdown": true
              }]
          }
          "@
          Invoke-RestMethod -Method post -ContentType 'Application/Json' -Body $body -Uri ${{ steps.myGetSecretAction.outputs.MICROSOFT-TEAMS-WEBHOOK-URI-Product }}
      - name: Set uEMAIL_FROMp Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
      #      - name: Install dependencies
      #        run: pip install -r requirements.txt
      - name: Send email
        run: python send_email.py --VAR_WORKFLOW "${{ github.workflow }}" --VAR_VERSION "${env:Version}" --VAR_REPO "${{ github.repository }}" --VAR_RUNNER "${{ github.run_number }}" --VAR_REF "${env:GITHUB_REF_NAME}" --VAR_COMMIT_MESSAGE "Commit Message - ${{ github.event.head_commit.message }}" --VAR_JOB_URL "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" --VAR_COUNT "${{ env.git_commit_count }}" --VAR_URL 'https://company.jfrog.io/artifactory/companydm-datamodeler/Product/Product${{ env.Version }}/${{ env.BRANCH_NAME }}/${{ github.run_number }}/company%20Product%20Portal%20${{ env.Version }}%20(64-bit)_${{ env.git_commit_count }}.exe'
        working-directory: C:\\actions-runner\\_work\\company-Product-MCL-NewUI\\company-Product-MCL-NewUI\\installs_repo\\workflowfiles\\email
        env:
          SUBJECT: "${{ github.workflow }} - ${{ env.Version }} - ${{ github.ref }} ${{ github.run_number }} Build successful"
          EMAIL_FROM: "[email protected]"
          EMAIL_TO: ${{ steps.myGetSecretAction.outputs.DM-GROUP-MAIL }}
          SMTP_USERNAME: "apikey"
          SMTP_PORT: "587"
          SMTP_SERVER: "smtp.sendgrid.net"
          SMTP_PASSWORD: "${{ steps.myGetSecretAction.outputs.MAIL-PASSWORD }}"
          EMAIL_TEMPLATE: "email_template.html"
      - name: Send failure mail
        if: failure()
        uses: juanformoso/action-send-mail@1
        with:
          # SMTP server address
          server_address: smtp.sendgrid.net
          # SMTP server port
          server_port: 587
          # Authenticate as this user to SMTP server
          username: apikey
          # Authenticate with this password to SMTP server
          password: ${{ steps.myGetSecretAction.outputs.MAIL-PASSWORD }}
          # Subject of mail message
          subject: ${{ github.workflow }} - ${{ env.Version }} - ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }} GitHubWorkflow_Build:${{ github.run_number }}
          # Body of mail message (might be a filename prefixed with file:// to read from)
          body: ${{ github.job }} job in worflow ${{ github.workflow }} - ${{ env.Version }} of ${{ github.repository }} has ${{ job.status }} in job url ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
          # Recipients mail addresses (separated with comma)
          to: ${{ steps.myGetSecretAction.outputs.DM-GROUP-MAIL }}
          # Email address of the sender
          from: [email protected]
          # Content-Type HTTP header (text/html or text/plain)
          content_type: text/html
          # Convert body from Markdown to HTML (set content_type input as text/html too)
          convert_markdown: true
      - name: Notify in Teams Channel for failure
        if: failure()
        shell: powershell
        run: |
          $body=@"
          {
              "@type": "MessageCard",
              "@context": "http://schema.org/extensions",
              "themeColor": "d73600",
              "summary": "Notification Summary",
              "sections": [{
                  "facts": [{
                      "name": "Workflow Name",
                      "value": "${env:GITHUB_WORKFLOW} ${env:Version}"
                  },{
                      "name": "Execution branch",
                      "value": "${env:GITHUB_REF_NAME}"
                  }, {
                      "name": "Workflow Build Number",
                      "value": "${{ github.run_number }}"
                  }, {
                      "name": "Repository",
                      "value": "${{ github.repository }}"
                  }, {
                      "name": "Commit Message",
                      "value": "${{ github.event.head_commit.message }}"
                  }, {
                      "name": "Job name",
                      "value": "${{ github.job }}"
                  },
                  {
                      "name": "Job URL",
                      "value": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
                  },{
                      "name": "Job status",
                      "value": "${{ job.status }}"
                  }],
                  "markdown": true
              }]
          }
          "@
          Invoke-RestMethod -Method post -ContentType 'Application/Json' -Body $body -Uri ${{ steps.myGetSecretAction.outputs.MICROSOFT-TEAMS-WEBHOOK-URI-Product }}

相关内容