build: update imported cosmwasm (#140) #7
This file contains 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: Deploy to Git | |
on: | |
push: | |
branches: | |
- main | |
- release/* | |
- hotfix** | |
permissions: | |
pull-requests: write | |
contents: write | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
build_shared_library: | |
strategy: | |
fail-fast: false | |
matrix: | |
# Shared libraries for Windows (.dll) currently do not work (https://github.com/CosmWasm/wasmvm/issues/389) | |
# and .dll builds are not deterministic. | |
# Deactivating this step to avoid polluting the git hostory. | |
os: [linux, macos] | |
include: | |
- os: linux | |
dockerfile_name: centos7 | |
shared_library_extension: so | |
- os: macos | |
dockerfile_name: cross | |
shared_library_extension: dylib | |
runs-on: ubuntu-latest | |
# execute only after pr merged | |
if: ${{ github.event.pusher.name != 'finschia-auto-pr[bot]' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.20' | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Prepare | |
id: prep | |
run: | | |
HASH_GHE=${{ github.sha }} | |
TAG=$(TZ=UTC-9 date '+%Y%m')${HASH_GHE:0:7} | |
echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache/${{ matrix.os }} | |
key: ${{ matrix.os }}-buildx-${{ steps.prep.outputs.tag }} | |
restore-keys: | | |
${{ matrix.os }}-buildx- | |
- name: Build docker | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./builders | |
file: ./builders/Dockerfile.${{ matrix.dockerfile_name }} | |
tags: finschia/wasmvm-builder-${{ matrix.dockerfile_name }}:latest | |
cache-from: type=local,src=/tmp/.buildx-cache/${{ matrix.os }} | |
cache-to: type=local,dest=/tmp/.buildx-cache/${{ matrix.os }}-new,mode=max | |
load: true | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache/${{ matrix.os }} | |
mv /tmp/.buildx-cache/${{ matrix.os }}-new /tmp/.buildx-cache/${{ matrix.os }} | |
- name: Build shared library | |
run: make release-build-${{ matrix.os }} | |
- name: Upload shared library | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.os }}-shared-library | |
path: ./internal/api/*.${{ matrix.shared_library_extension }} | |
deploy_to_git: | |
runs-on: ubuntu-latest | |
needs: build_shared_library | |
outputs: | |
updated: ${{ steps.cd.outputs.need_update }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Get app token | |
uses: tibdex/github-app-token@v1 | |
id: generate-token | |
with: | |
app_id: ${{ secrets.FINSCHIA_AUTO_PR_APP_ID }} | |
private_key: ${{ secrets.FINSCHIA_AUTO_PR_APP_PRIVATE_KEY }} | |
# https://github.com/tibdex/github-app-token/issues/54#issuecomment-1410471261 | |
env: | |
OPENSSL_CONF: /dev/null | |
- name: Download shared library | |
uses: actions/download-artifact@v3 | |
with: | |
path: ./artifacts | |
- name: Check diff | |
id: cd | |
run: | | |
mv ./artifacts/linux-shared-library/* ./internal/api | |
mv ./artifacts/macos-shared-library/* ./internal/api | |
chmod 755 internal/api/*.{so,dylib} | |
git add . | |
if ! git diff --cached --exit-code ; then | |
echo "need_update=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "need_update=false" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Check PR | |
if: steps.cd.outputs.need_update=='true' | |
run: | | |
gh pr list --state open --json author,number | jq -r '.[] | select(.author.login == "app/finschia-auto-pr") | .number' | while read -r pr_number; do | |
gh pr close -d -c "This pr is out of date." $pr_number | |
done | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} | |
- name: Get latest PR | |
id: prn | |
run: | | |
LATEST_PR_NUMBER=$(git log --format=%B -n 1 | head -n 1 | grep -oP '.*\(#\K\d+(?=\))') | |
echo "latest_pr_number=${LATEST_PR_NUMBER}" >> "$GITHUB_OUTPUT" | |
- name: Create commit | |
if: steps.cd.outputs.need_update=='true' | |
run: | | |
git config user.name "finschia-auto-pr[bot]" | |
git config user.email "141415241+finschia-auto-pr[bot]@users.noreply.github.com" | |
git commit -m "chore: auto generate shared library" | |
- name: Create pull request | |
if: steps.cd.outputs.need_update=='true' | |
id: cpr | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ steps.generate-token.outputs.token }} | |
signoff: true | |
branch: auto_shared_library_${{ steps.prn.outputs.latest_pr_number }} | |
base: ${{ github.ref_name }} | |
delete-branch: true | |
title: 'chore: (auto)update shared library' | |
body: | | |
# Description | |
Update shared library | |
- Updated shared library | |
- This is caused by #${{ steps.prn.outputs.latest_pr_number }}" | |
- Auto-generated by [create-pull-request][1] | |
## Types of changes | |
- [ ] Bug fix (changes which fixes an issue) | |
- [ ] New feature (changes which adds functionality) | |
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) | |
- [x] ETC (build, ci, docs, perf, refactor, style, test) | |
[1]: https://github.com/peter-evans/create-pull-request | |
labels: automerge | |
draft: false | |
- name: Enable Pull Request Automerge | |
if: steps.cpr.outputs.pull-request-operation == 'created' | |
run: gh pr merge --auto --squash --delete-branch ${{ steps.cpr.outputs.pull-request-number }} | |
env: | |
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} | |
get-version: # emit package version using `cargo tree -i` | |
name: Get Package Version | |
runs-on: ubuntu-latest | |
needs: [build_shared_library, deploy_to_git] | |
if: | | |
always() && | |
( needs.build_shared_library.result=='success' || needs.build_shared_library.result=='skipped' ) && | |
( github.event.pusher.name == 'finschia-auto-pr[bot]' || needs.deploy_to_git.outputs.updated=='false' ) | |
outputs: | |
package-version: ${{ steps.get-package-version.outputs.version }} | |
latest-tag: ${{ steps.get-latest-tag.outputs.tag }} | |
steps: | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: 1.60.0 | |
profile: minimal | |
override: true | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Get latest tag | |
id: get-latest-tag | |
uses: actions-ecosystem/action-get-latest-tag@v1 | |
- name: Get package version | |
id: get-package-version | |
working-directory: ./libwasmvm | |
run: | | |
VERSION=$(cargo tree -i wasmvm | grep -oE "[0-9]+(\.[0-9]+){2}[\+\-][0-9]+(\.[0-9]+){2}(-[0-9a-zA-Z.]+)*(\+[0-9a-zA-Z.\-]+)*") | |
echo ::set-output name=version::v$VERSION | |
push-tag: # if the version does not exist as git tag, push it | |
name: Push Tag | |
needs: [build_shared_library, get-version] | |
if: | | |
always() && | |
( needs.build_shared_library.result=='success' || needs.build_shared_library.result=='skipped' ) && | |
( needs.get-version.outputs.package-version != needs.get-version.outputs.latest-tag ) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Push Tag to GitHub | |
run: | | |
curl -s -H "Authorization: token ${GITHUB_TOKEN}" \ | |
-d "{\"ref\": \"refs/tags/${{ needs.get-version.outputs.package-version }}\", \"sha\": \"${GITHUB_SHA}\"}" \ | |
"https://api.github.com/repos/${GITHUB_REPOSITORY}/git/refs" | |
update-releases: | |
name: Update releases | |
needs: [build_shared_library, push-tag] | |
if: | | |
always() && | |
( needs.build_shared_library.result=='success' || needs.build_shared_library.result=='skipped' ) && | |
( needs.push-tag.result=='success' ) | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: set up | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.20' | |
id: go | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Build docker image | |
run: cd builders && make docker-image-alpine && make docker-image-cross | |
- name: Build & Test static library | |
run: make release-build-alpine | |
- name: Build static library for MacOS | |
run: make release-build-macos-static | |
- name: Collect artifacts | |
run: | | |
mkdir artifacts | |
cp ./internal/api/libwasmvm_muslc.a ./artifacts/libwasmvm_muslc.x86_64.a | |
cp ./internal/api/libwasmvm_muslc.aarch64.a ./artifacts/libwasmvm_muslc.aarch64.a | |
cp ./internal/api/libwasmvmstatic_darwin.a ./artifacts/libwasmvmstatic_darwin.a | |
- name: Create checksums | |
working-directory: ./artifacts | |
run: sha256sum * > checksums.txt && cat checksums.txt | |
- name: Create Release | |
uses: softprops/[email protected] | |
with: | |
tag_name: ${{ needs.get-version.outputs.package-version }} | |
body: ${{ github.event.pull_request.body }} | |
files: | | |
./artifacts/* | |
draft: false | |
prerelease: false |