Add build system #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ci | |
| on: | |
| push: | |
| branches: | |
| - 'main' | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} | |
| cancel-in-progress: true | |
| permissions: {} | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| platforms: ${{ steps.platforms.outputs.platforms }} | |
| steps: | |
| - name: platforms matrix | |
| id: platforms | |
| run: | | |
| platforms="[ | |
| {\"os\": \"darwin\", \"arch\": \"amd64\"}, | |
| {\"os\": \"darwin\", \"arch\": \"arm64\"}, | |
| {\"os\": \"linux\", \"arch\": \"amd64\"}, | |
| {\"os\": \"linux\", \"arch\": \"arm64\"}, | |
| {\"os\": \"linux\", \"arch\": \"arm\", \"arm\": \"6\"}, | |
| {\"os\": \"linux\", \"arch\": \"arm\", \"arm\": \"7\"}, | |
| {\"os\": \"windows\", \"arch\": \"amd64\"}, | |
| {\"os\": \"windows\", \"arch\": \"arm64\"} | |
| ]" | |
| echo "platforms=$(echo $platforms | jq -c .)" >> $GITHUB_OUTPUT | |
| lint: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| checks: write | |
| contents: read | |
| pull-requests: read | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: setup go | |
| uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 | |
| with: | |
| go-version: "^1.23" | |
| - name: check dependencies | |
| run: | | |
| go mod tidy | |
| git diff --exit-code go.mod | |
| - name: lint | |
| uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 | |
| build: | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| platform: ${{fromJson(needs.prepare.outputs.platforms)}} | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: build | |
| uses: ./.github/actions/build-wpm | |
| with: | |
| go-os: ${{ matrix.platform.os }} | |
| go-arm: ${{ matrix.platform.arm }} | |
| go-arch: ${{ matrix.platform.arch }} | |
| - name: list artifacts | |
| run: ls -alh ./build | |
| - name: upload artifacts | |
| uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 | |
| with: | |
| # see $TARGET in .github/actions/build-wpm/scripts/.variables | |
| name: wpm-${{ matrix.platform.os }}-${{ matrix.platform.arch }}${{ matrix.platform.arm && '-v'}}${{ matrix.platform.arm }} | |
| path: ./build/* | |
| if-no-files-found: error | |
| - name: s3 upload | |
| if: ${{ github.ref_type == 'branch' }} | |
| uses: ./.github/actions/s3-upload | |
| with: | |
| source: ./build | |
| target: ${{ github.ref_name }} | |
| vault: ${{ secrets.OP_VAULT }} | |
| bucket: ${{ secrets.S3_BUCKET }} | |
| rclone-config: ${{ secrets.RCLONE_CONFIG }} | |
| token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | |
| pr-comment: | |
| needs: [prepare, build] | |
| runs-on: ubuntu-latest | |
| if: ${{ github.head_ref && github.head_ref != null }} | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: prepare | |
| id: find-existing-comment | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 | |
| with: | |
| script: | | |
| return (await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| })).data.find((comment) => comment.body.includes('wpm cli builds'))?.id || null | |
| - name: comment body | |
| id: comment-body | |
| run: | | |
| body=":package: wpm cli builds :package: \n\n" | |
| for platform in ${{fromJson(needs.prepare.outputs.platforms)}}; do | |
| build_url="https://cli-builds.wpm.so/${{ github.ref_name }}/wpm-${platform.os}-${platform.arch}${platform.arm && '-v'}${platform.arm}" | |
| body="$body- ${platform.os}/${platform.arch}${platform.arm && '/v'}${platform.arm} - [build]($build_url) | [checksum]($build_url.sha256)\n" | |
| done | |
| delimiter="${body//$'\n'/'%0A'}" | |
| echo "body<<${delimiter}" >> $GITHUB_OUTPUT | |
| echo "$body" >> $GITHUB_OUTPUT | |
| echo "${delimiter}" >> $GITHUB_OUTPUT | |
| env: | |
| S3_URL: "https://cli-builds.wpm.so" | |
| - name: create comment | |
| if: ${{ steps.comment-body.outputs.result == null }} | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| repo: context.repo.repo, | |
| owner: context.repo.owner, | |
| issue_number: context.issue.number, | |
| body: `${{ steps.comment-body.outputs.body }}`, | |
| }); | |
| - name: update comment | |
| if: ${{ steps.comment-body.outputs.result != null }} | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 | |
| with: | |
| script: | | |
| github.rest.issues.updateComment({ | |
| repo: context.repo.repo, | |
| owner: context.repo.owner, | |
| body: `${{ steps.comment-body.outputs.body }}`, | |
| comment_id: ${{ steps.comment-body.outputs.result }}, | |
| }); |