Skip to content

Merge pull request #92 from trywpm/dependabot/go_modules/github.com/s… #206

Merge pull request #92 from trywpm/dependabot/go_modules/github.com/s…

Merge pull request #92 from trywpm/dependabot/go_modules/github.com/s… #206

Workflow file for this run

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@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.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@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
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' && github.actor != 'dependabot[bot]' }}
run: aws s3 cp build/ s3://wpm-cli-builds/${{ github.event.number && github.event.number != null && github.event.number || 'latest' }}/ --recursive --endpoint-url ${{ secrets.S3_ENDPOINT_URL }} --region auto --checksum-algorithm CRC32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
pr-comment:
needs: [prepare, build]
runs-on: ubuntu-latest
if: ${{ github.head_ref && github.head_ref != null && github.actor != 'dependabot[bot]' }}
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
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
with:
script: |
const platforms = JSON.parse(${{ toJson(needs.prepare.outputs.platforms) }})
const builds = platforms.map(({ os, arm, arch }) => {
const buildPath = `wpm-${os}-${arch}${arm ? `-v${arm}` : ''}`
const buildUrl = `https://pub-bea4f3d05c4f49e0b54ccf1dad0da103.r2.dev/${{ github.event.number }}/${buildPath}${os === 'windows' ? '.exe' : ''}`
const spec = `${os}/${arch}${arm ? `/v${arm}` : ''}`
return `- \`${spec}\` - [\`build\`](${buildUrl}) [\`checksum\`](${buildUrl}.sha256)`
}).join('\n')
return `:package: wpm cli builds :package:\n${builds}\n`
- name: create comment
if: ${{ steps.find-existing-comment.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.result }},
});
- name: update comment
if: ${{ steps.find-existing-comment.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.result }},
comment_id: ${{ steps.find-existing-comment.outputs.result }},
});
release:
needs: [prepare, build]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
permissions:
contents: write
steps:
- name: download artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 #v4.3.0
with:
path: ./build
pattern: wpm-*
merge-multiple: true
- name: checksums.txt
working-directory: ./build
run: |
rm -f checksums.txt
for file in *.sha256; do
echo "$(cat $file)" >> checksums.txt
done
shasum -a 256 -U -c checksums.txt
- name: create release
id: create-release
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
with:
script: |
const tagName = context.ref.replace('refs/tags/', '')
const isPreRelease = tagName.includes('-rc');
const { data: { upload_url: uploadUrl } } = await github.rest.repos.createRelease({
draft: true,
name: tagName,
tag_name: tagName,
repo: context.repo.repo,
prerelease: isPreRelease,
owner: context.repo.owner,
target_commitish: context.sha,
body: '> todo: add release notes',
});
return uploadUrl
- name: upload release assets
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
with:
script: |
const fs = require('fs');
let uploadUrl = ${{ steps.create-release.outputs.result }}
const templateMarkerPos = uploadUrl.indexOf("{");
if (templateMarkerPos !== -1) {
uploadUrl = uploadUrl.substring(0, templateMarkerPos);
}
const files = fs.readdirSync('./build').map((file) => `./build/${file}`)
for (const file of files) {
const name = file.replace('./build/', '')
const response = await github.request({
method: 'POST',
url: uploadUrl + `?name=${name}`,
headers: {
'content-length': fs.statSync(file).size,
'authorization': `token ${process.env.GITHUB_TOKEN}`,
'content-type': name.endsWith('.txt') || name.endsWith('.sha256') ? 'text/plain' : 'application/octet-stream',
},
name,
data: fs.readFileSync(file),
});
if (response.status !== 201) {
throw new Error(`failed to upload ${name}`)
}
core.info(`uploaded ${name}`)
}