|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/publish-go-tester-task.md |
| 2 | +name: Publish Tester Build |
| 3 | + |
| 4 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
| 5 | +on: |
| 6 | + create: |
| 7 | + push: |
| 8 | + paths: |
| 9 | + - ".github/workflows/publish-go-tester-task.ya?ml" |
| 10 | + - "go.mod" |
| 11 | + - "go.sum" |
| 12 | + - "Taskfile.ya?ml" |
| 13 | + - "DistTasks.ya?ml" |
| 14 | + - "**.go" |
| 15 | + pull_request: |
| 16 | + paths: |
| 17 | + - ".github/workflows/publish-go-tester-task.ya?ml" |
| 18 | + - "go.mod" |
| 19 | + - "go.sum" |
| 20 | + - "Taskfile.ya?ml" |
| 21 | + - "DistTasks.ya?ml" |
| 22 | + - "**.go" |
| 23 | + workflow_dispatch: |
| 24 | + repository_dispatch: |
| 25 | + |
| 26 | +env: |
| 27 | + # As defined by the Taskfile's PROJECT_NAME variable |
| 28 | + PROJECT_NAME: dfu-discovery |
| 29 | + # As defined by the Taskfile's DIST_DIR variable |
| 30 | + DIST_DIR: dist |
| 31 | + |
| 32 | +jobs: |
| 33 | + run-determination: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + result: ${{ steps.determination.outputs.result }} |
| 37 | + steps: |
| 38 | + - name: Determine if the rest of the workflow should run |
| 39 | + id: determination |
| 40 | + run: | |
| 41 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 42 | + TAG_REGEX="refs/tags/.*" |
| 43 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 44 | + if [[ |
| 45 | + ("${{ github.event_name }}" != "create" || |
| 46 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX) && |
| 47 | + ! "${{ github.ref }}" =~ $TAG_REGEX |
| 48 | + ]]; then |
| 49 | + # Run the other jobs. |
| 50 | + RESULT="true" |
| 51 | + else |
| 52 | + # There is no need to run the other jobs. |
| 53 | + RESULT="false" |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + package-name-prefix: |
| 59 | + needs: run-determination |
| 60 | + if: needs.run-determination.outputs.result == 'true' |
| 61 | + runs-on: ubuntu-latest |
| 62 | + outputs: |
| 63 | + prefix: ${{ steps.calculation.outputs.prefix }} |
| 64 | + steps: |
| 65 | + - name: package name prefix calculation |
| 66 | + id: calculation |
| 67 | + run: | |
| 68 | + PACKAGE_NAME_PREFIX="test" |
| 69 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 70 | + PACKAGE_NAME_PREFIX="$PACKAGE_NAME_PREFIX-${{ github.event.number }}" |
| 71 | + fi |
| 72 | + PACKAGE_NAME_PREFIX="$PACKAGE_NAME_PREFIX-${{ github.sha }}-" |
| 73 | +
|
| 74 | + echo "prefix=$PACKAGE_NAME_PREFIX" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + build: |
| 77 | + needs: package-name-prefix |
| 78 | + name: Build ${{ matrix.os.name }} |
| 79 | + runs-on: ubuntu-latest |
| 80 | + |
| 81 | + strategy: |
| 82 | + matrix: |
| 83 | + os: |
| 84 | + - task: Windows_32bit |
| 85 | + path: "*Windows_32bit.zip" |
| 86 | + name: Windows_X86-32 |
| 87 | + - task: Windows_64bit |
| 88 | + path: "*Windows_64bit.zip" |
| 89 | + name: Windows_X86-64 |
| 90 | + - task: Linux_32bit |
| 91 | + path: "*Linux_32bit.tar.gz" |
| 92 | + name: Linux_X86-32 |
| 93 | + - task: Linux_64bit |
| 94 | + path: "*Linux_64bit.tar.gz" |
| 95 | + name: Linux_X86-64 |
| 96 | + - task: Linux_ARMv6 |
| 97 | + path: "*Linux_ARMv6.tar.gz" |
| 98 | + name: Linux_ARMv6 |
| 99 | + - task: Linux_ARMv7 |
| 100 | + path: "*Linux_ARMv7.tar.gz" |
| 101 | + name: Linux_ARMv7 |
| 102 | + - task: Linux_ARM64 |
| 103 | + path: "*Linux_ARM64.tar.gz" |
| 104 | + name: Linux_ARM64 |
| 105 | + - task: macOS_64bit |
| 106 | + path: "*macOS_64bit.tar.gz" |
| 107 | + name: macOS_64 |
| 108 | + - task: macOS_ARM64 |
| 109 | + path: "*macOS_ARM64.tar.gz" |
| 110 | + name: macOS_ARM64 |
| 111 | + |
| 112 | + steps: |
| 113 | + - name: Checkout repository |
| 114 | + uses: actions/checkout@v3 |
| 115 | + |
| 116 | + - name: Install Task |
| 117 | + uses: arduino/setup-task@v1 |
| 118 | + with: |
| 119 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + version: 3.x |
| 121 | + |
| 122 | + - name: Download dfu-util |
| 123 | + run: task download-dfu-util |
| 124 | + |
| 125 | + - name: Build |
| 126 | + run: | |
| 127 | + PACKAGE_NAME_PREFIX=${{ needs.package-name-prefix.outputs.prefix }} |
| 128 | + export PACKAGE_NAME_PREFIX |
| 129 | + task dist:${{ matrix.os.task }} |
| 130 | +
|
| 131 | + # Transfer builds to artifacts job |
| 132 | + - name: Upload build artifact |
| 133 | + uses: actions/upload-artifact@v3 |
| 134 | + with: |
| 135 | + path: ${{ env.DIST_DIR }}/${{ matrix.os.path }} |
| 136 | + name: ${{ matrix.os.name }} |
| 137 | + |
| 138 | + checksums: |
| 139 | + needs: |
| 140 | + - build |
| 141 | + - package-name-prefix |
| 142 | + runs-on: ubuntu-latest |
| 143 | + |
| 144 | + steps: |
| 145 | + - name: Download build artifacts |
| 146 | + uses: actions/download-artifact@v3 |
| 147 | + |
| 148 | + - name: Create checksum file |
| 149 | + run: | |
| 150 | + TAG="${{ needs.package-name-prefix.outputs.prefix }}git-snapshot" |
| 151 | + declare -a artifacts=($(ls -d */)) |
| 152 | + for artifact in ${artifacts[@]} |
| 153 | + do |
| 154 | + cd $artifact |
| 155 | + checksum=$(sha256sum ${{ env.PROJECT_NAME }}_${TAG}*) |
| 156 | + cd .. |
| 157 | + echo $checksum >> ${TAG}-checksums.txt |
| 158 | + done |
| 159 | +
|
| 160 | + - name: Upload checksum artifact |
| 161 | + uses: actions/upload-artifact@v3 |
| 162 | + with: |
| 163 | + path: ./*checksums.txt |
| 164 | + name: checksums |
0 commit comments