https://kotlinlang.org logo
#touchlab-tools
Title
# touchlab-tools
h

Håkon Pettersen

11/08/2023, 2:29 PM
Hi, question regarding KMMBridge build-flow. We are having some trouble getting our github-action to work. It fails on Build.main. It doesn't seem to be able to resolve the env-variables USERNAME and TOKEN. Is there maybe the placement of the env-variables that is wrong in the script? I have verified that the env-variables are valid in another action. ios-publish.yml
Copy code
name: iOS Publish
on:
  push:
#  push:
#    branches:
#      - "main"
jobs:
  call-kmmbridge-publish:
    permissions:
      contents: write
      packages: write
    uses: ./.github/workflows/faktory-build.yml
    with:
      jvmVersion: 17
      libraryVersion: LIBRARY_VERSION
faktory-build.yml
Copy code
name: KMM Bridge Github Workflow
on:
  workflow_call:
    inputs:
      module:
        description: The module name to run the task on if you have multiple kmp modules
        required: false
        type: string
      publishTask:
        description: 'The publish task to call if not kmmBridgePublish'
        default: 'kmmBridgePublish'
        required: false
        type: string
      jvmVersion:
        description: 'JVM Version to use. Will be passed to java-version parameter of setup-java'
        default: '11'
        required: false
        type: string
      runsOn:
        description: 'Host parameter to pass to runs-on'
        default: 'macos-12'
        required: false
        type: string
      libraryVersion:
        description: 'Version key from gradle.properties'
        required: true
        type: string
      retainBuildBranch:
        description: 'Keep the build branch after build complete'
        default: false
        type: boolean
    secrets:
      gradle_params:
        required: false

jobs:
  kmmbridgepublish:
    concurrency: "kmmbridgepublish-${{ github.repository }}"
    runs-on: ${{ inputs.runsOn }}

    env:
      MODULE: ${{ inputs.module != '' && format('{0}:',inputs.module) || '' }}
      USERNAME: ${{ secrets.USERNAME }}
      TOKEN: ${{ secrets.TOKEN }}

    steps:
      - name: Checkout the repo with tags
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-java@v2
        with:
          distribution: "adopt"
          java-version: ${{ inputs.jvmVersion }}

      - name: Validate Gradle Wrapper
        uses: gradle/wrapper-validation-action@v1

      - name: Cache build tooling
        uses: actions/cache@v3
        with:
          path: |
            ~/.gradle/caches
            ~/.konan
          key: ${{ runner.os }}-v4-${{ hashFiles('*.gradle.kts') }}

      - name: Build Main
        run: ./gradlew ${{ env.MODULE }}${{ inputs.publishTask }} -PENABLE_PUBLISHING=true -PGITHUB_PUBLISH_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_REPO=${{ github.repository }} ${{ secrets.gradle_params }} --no-daemon --stacktrace
        env:
          GRADLE_OPTS: -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx3g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=512m"

      - uses: touchlab/autoversion-finishrelease@main
        id: autoversion-finishrelease
        with:
          commitMessage: "Snute Shared Library SPM package release for ${{ inputs.libraryVersion }}"
          tagMessage: "Snute Shared Library release version ${{ inputs.libraryVersion }}"
          tagVersion: ${{ inputs.libraryVersion }}
          branchName: "build-${{ inputs.libraryVersion }}"

      - uses: touchlab/autoversion-tagmarker@main
        id: autoversion-tagmarker-cleanup
        with:
          nextVersion: ${{ inputs.libraryVersion }}
          cleanupMarkers: 'true'

      - name: Delete branch
        if: (!inputs.retainBuildBranch) && (!cancelled())
        uses: touchlab/action-delete-branch@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branches: "build-${{ inputs.libraryVersion }}"
Workflows that call reusable workflows in the same organization or enterprise can use the
inherit
keyword to implicitly pass the secrets.
Copy code
jobs:
  call-workflow-passing-data:
    uses: octo-org/example-repo/.github/workflows/reusable-workflow.yml@main
    with:
      config-path: .github/labeler.yml
    secrets: inherit
Secrets aren't automatically available in the called workflow, except some GitHub provides values:
When a reusable workflow is triggered by a caller workflow, the
github
context is always associated with the caller workflow. The called workflow is automatically granted access to
github.token
and
secrets.GITHUB_TOKEN
.
h

Håkon Pettersen

11/16/2023, 8:23 AM
inherit
keyword solved the missing enviroment-variables in the reusable workflow, thanks 🙂
👍 1
3 Views