-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Release-core | ||
on: | ||
workflow_dispatch: | ||
|
||
env: | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
GO_VERSION: "1.18" | ||
|
||
jobs: | ||
ci-pass: | ||
name: CI is green | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build_release_assets | ||
steps: | ||
- run: exit 0 | ||
|
||
build_release_assets: | ||
name: Build and upload assets | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- target: ios | ||
host: macos-latest | ||
- target: android | ||
host: ubuntu-latest | ||
runs-on: ${{ matrix.config.host }} | ||
env: | ||
TARGET: ${{ matrix.config.target }} | ||
steps: | ||
- name: Setup golang | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Cache go modules (Linux) | ||
if: matrix.config.host == 'ubuntu-latest' | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg/mod | ||
key: ${{ matrix.config.host }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ matrix.config.host }}-go- | ||
- name: Cache go modules (macOS) | ||
if: matrix.config.host == 'macos-latest' | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/Library/Caches/go-build | ||
~/go/pkg/mod | ||
key: ${{ matrix.config.host }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ matrix.config.host }}-go- | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ env.BRANCH }} | ||
|
||
- id: check_asset | ||
name: Check asset | ||
run: | | ||
cd ci | ||
go run ./cmd/check_asset_core | ||
- name: Checkout core | ||
if: steps.check_asset.outputs.skip_build != 'true' | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: 'niuhuan/pikapika-go-core' | ||
token: ${{ secrets.GH_TOKEN }} | ||
path: 'go' | ||
|
||
- name: Build (ios) | ||
if: steps.check_asset.outputs.skip_build != 'true' && matrix.config.target == 'ios' | ||
run: | | ||
sh scripts/bind-ios.sh | ||
- name: Build (android) | ||
if: steps.check_asset.outputs.skip_build != 'true' && matrix.config.target == 'android' | ||
run: | | ||
sh scripts/bind-android-debug.sh | ||
- name: Upload Asset (All) | ||
if: steps.check_asset.outputs.skip_build != 'true' | ||
run: | | ||
zip -r core.zip go/mobile/lib | ||
cd ci | ||
go run ./cmd/upload_asset_core | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"ci/commons" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func main() { | ||
// get ghToken | ||
ghToken := os.Getenv("GH_TOKEN") | ||
if ghToken == "" { | ||
println("Env ${GH_TOKEN} is not set") | ||
os.Exit(1) | ||
} | ||
// get version | ||
version := commons.LoadVersion() | ||
// get TARGET | ||
target := os.Getenv("TARGET") | ||
if target == "" { | ||
println("Env ${TARGET} is not set") | ||
os.Exit(1) | ||
} | ||
// | ||
var releaseFileName = fmt.Sprintf("core-%v-%v.zip", version.Code, target) | ||
// get version | ||
getReleaseRequest, err := http.NewRequest( | ||
"GET", | ||
fmt.Sprintf("https://api.github.com/repos/%v/%v/releases/tags/%v", commons.Owner, commons.Repo, version.Code), | ||
nil, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
getReleaseRequest.Header.Set("User-Agent", commons.Ua) | ||
getReleaseRequest.Header.Set("Authorization", "token "+ghToken) | ||
getReleaseResponse, err := http.DefaultClient.Do(getReleaseRequest) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer getReleaseResponse.Body.Close() | ||
if getReleaseResponse.StatusCode == 404 { | ||
panic("NOT FOUND RELEASE") | ||
} | ||
buff, err := ioutil.ReadAll(getReleaseResponse.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
var release commons.Release | ||
err = json.Unmarshal(buff, &release) | ||
if err != nil { | ||
println(string(buff)) | ||
panic(err) | ||
} | ||
for _, asset := range release.Assets { | ||
if asset.Name == releaseFileName { | ||
println("::set-output name=skip_build::true") | ||
os.Exit(0) | ||
} | ||
} | ||
print("::set-output name=skip_build::false") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"ci/commons" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"path" | ||
) | ||
|
||
func main() { | ||
// get ghToken | ||
ghToken := os.Getenv("GH_TOKEN") | ||
if ghToken == "" { | ||
println("Env ${GH_TOKEN} is not set") | ||
os.Exit(1) | ||
} | ||
// get version | ||
version := commons.LoadVersion() | ||
// get TARGET | ||
target := os.Getenv("TARGET") | ||
if target == "" { | ||
println("Env ${TARGET} is not set") | ||
os.Exit(1) | ||
} | ||
// | ||
var releaseFileName = fmt.Sprintf("core-%v-%v.zip", version.Code, target) | ||
var releaseFilePath = "core.zip" | ||
var contentLength int64 | ||
releaseFilePath = path.Join("..", releaseFilePath) | ||
info, err := os.Stat(releaseFilePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
contentLength = info.Size() | ||
// get version | ||
getReleaseRequest, err := http.NewRequest( | ||
"GET", | ||
fmt.Sprintf("https://api.github.com/repos/%v/%v/releases/tags/%v", commons.Owner, commons.Repo, version.Code), | ||
nil, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
getReleaseRequest.Header.Set("User-Agent", commons.Ua) | ||
getReleaseRequest.Header.Set("Authorization", "token "+ghToken) | ||
getReleaseResponse, err := http.DefaultClient.Do(getReleaseRequest) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer getReleaseResponse.Body.Close() | ||
if getReleaseResponse.StatusCode == 404 { | ||
panic("NOT FOUND RELEASE") | ||
} | ||
buff, err := ioutil.ReadAll(getReleaseResponse.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
var release commons.Release | ||
err = json.Unmarshal(buff, &release) | ||
if err != nil { | ||
println(string(buff)) | ||
panic(err) | ||
} | ||
file, err := os.Open(releaseFilePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file.Close() | ||
uploadUrl := fmt.Sprintf("https://uploads.github.com/repos/%v/%v/releases/%v/assets?name=%v", commons.Owner, commons.Repo, release.Id, releaseFileName) | ||
uploadRequest, err := http.NewRequest("POST", uploadUrl, file) | ||
if err != nil { | ||
panic(err) | ||
} | ||
uploadRequest.Header.Set("User-Agent", commons.Ua) | ||
uploadRequest.Header.Set("Authorization", "token "+ghToken) | ||
uploadRequest.Header.Set("Content-Type", "application/octet-stream") | ||
uploadRequest.ContentLength = contentLength | ||
uploadResponse, err := http.DefaultClient.Do(uploadRequest) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if uploadResponse.StatusCode != 201 { | ||
buff, err = ioutil.ReadAll(uploadResponse.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
println(string(buff)) | ||
panic("NOT 201") | ||
} | ||
} |