Skip to content

Commit

Permalink
chore: add an automatic build shared library ci (#119)
Browse files Browse the repository at this point in the history
* chore: add an automatic build shared library ci

Signed-off-by: 170210 <j170210@icloud.com>

* chore: add checksum file

Signed-off-by: 170210 <j170210@icloud.com>

* fixup: fix for comment

Signed-off-by: 170210 <j170210@icloud.com>

* fixup: use git diff instead of checksum

Signed-off-by: 170210 <j170210@icloud.com>

* fixup: fix for comment

Signed-off-by: 170210 <j170210@icloud.com>

---------

Signed-off-by: 170210 <j170210@icloud.com>
  • Loading branch information
170210 authored Sep 11, 2023
1 parent f4e948f commit bf6d128
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 additions & 0 deletions .github/workflows/deploy_to_git.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Deploy to Git

on:
pull_request:
types:
- closed

permissions:
pull-requests: write
contents: write

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.pull_request.merged == true && github.event.pull_request.user.login != '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
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[bot]") | .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: 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: ${{ github.head_ref }}_shared_library_test
base: ${{ github.ref }}
delete-branch: true
title: 'chore: (auto)update shared library'
body: |
# Description
Update shared library
- Updated shared library
- This is caused by #${{ github.event.pull_request.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 }}

0 comments on commit bf6d128

Please sign in to comment.