|
| 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 | +env: |
| 5 | + # See: https://github.com/actions/setup-go/tree/v2#readme |
| 6 | + GO_VERSION: "1.16" |
| 7 | + |
| 8 | +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows |
| 9 | +on: |
| 10 | + create: |
| 11 | + push: |
| 12 | + paths: |
| 13 | + - ".github/workflows/publish-go-tester-task.ya?ml" |
| 14 | + - "go.mod" |
| 15 | + - "go.sum" |
| 16 | + - "Taskfile.ya?ml" |
| 17 | + - "**.go" |
| 18 | + pull_request: |
| 19 | + paths: |
| 20 | + - ".github/workflows/publish-go-tester-task.ya?ml" |
| 21 | + - "go.mod" |
| 22 | + - "go.sum" |
| 23 | + - "Taskfile.ya?ml" |
| 24 | + - "**.go" |
| 25 | + workflow_dispatch: |
| 26 | + repository_dispatch: |
| 27 | + |
| 28 | +jobs: |
| 29 | + run-determination: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + outputs: |
| 32 | + result: ${{ steps.determination.outputs.result }} |
| 33 | + steps: |
| 34 | + - name: Determine if the rest of the workflow should run |
| 35 | + id: determination |
| 36 | + run: | |
| 37 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 38 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 39 | + if [[ \ |
| 40 | + "${{ github.event_name }}" != "create" || \ |
| 41 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ |
| 42 | + ]]; then |
| 43 | + # Run the other jobs. |
| 44 | + RESULT="true" |
| 45 | + else |
| 46 | + # There is no need to run the other jobs. |
| 47 | + RESULT="false" |
| 48 | + fi |
| 49 | +
|
| 50 | + echo "::set-output name=result::$RESULT" |
| 51 | +
|
| 52 | + build: |
| 53 | + needs: run-determination |
| 54 | + if: needs.run-determination.outputs.result == 'true' |
| 55 | + runs-on: ubuntu-latest |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Set environment variables |
| 59 | + run: | |
| 60 | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable |
| 61 | + echo "BUILD_ARCHIVE_PATH=${{ runner.temp }}/libraries-repository-engine_${{ github.sha }}_Linux_64bit.zip" >> "$GITHUB_ENV" |
| 62 | +
|
| 63 | + - name: Checkout repository |
| 64 | + uses: actions/checkout@v2 |
| 65 | + |
| 66 | + - name: Install Go |
| 67 | + uses: actions/setup-go@v2 |
| 68 | + with: |
| 69 | + go-version: ${{ env.GO_VERSION }} |
| 70 | + |
| 71 | + - name: Install Task |
| 72 | + uses: arduino/setup-task@v1 |
| 73 | + with: |
| 74 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + version: 3.x |
| 76 | + |
| 77 | + - name: Build application |
| 78 | + run: task go:build |
| 79 | + |
| 80 | + # actions/upload-artifact does not maintain file permissions. Putting the executable in an archive avoids the |
| 81 | + # application becoming non-executable. |
| 82 | + - name: Archive build |
| 83 | + run: | |
| 84 | + zip \ |
| 85 | + -j \ |
| 86 | + "${{ env.BUILD_ARCHIVE_PATH }}" \ |
| 87 | + "./libraries-repository-engine" \ |
| 88 | + "./LICENSE.txt" |
| 89 | +
|
| 90 | + - name: Save binary as workflow artifact |
| 91 | + uses: actions/upload-artifact@v2 |
| 92 | + with: |
| 93 | + if-no-files-found: error |
| 94 | + path: ${{ env.BUILD_ARCHIVE_PATH }} |
| 95 | + name: libraries-repository-engine |
0 commit comments