-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (133 loc) · 4.8 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# trunk-ignore-all(checkov/CKV2_GHA_1)
# This is a basic workflow to help you get started with Actions
name: build
# Controls when the workflow will run
on:
# Triggers after test.yml
# workflow_run:
# workflows: [functionality]
# types:
# - completed
push:
tags:
- "**"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
#Job1
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# outputs:
# cache-key: ${{ steps.build-script.outputs.cache_key }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.20.0'
# Runs a set of commands using the runners shell
- name: build-script
id: build-script
run: |
cd ${{ github.workspace }}
mkdir bin
mkdir bin/flowcat-darwin-arm64
mkdir bin/flowcat-linux-386
mkdir bin/flowcat-linux-amd64
go test release_test.go
if [ `echo $?` -ne 0 ]; then exit 1; fi
ls bin/flowcat-darwin-arm64/
# echo "${{ hashFiles('bin/flowcat-darwin-arm64/**') }}"
# echo "cache_key=${{ hashFiles('bin/flowcat-darwin-arm64/**') }}" >> $GITHUB_OUTPUT
- name: upload-darwin-arm64-cache
id: darwin-arm64-cache
uses: actions/cache/save@v3
with:
path: |
bin
bin/*
bin/flowcat-darwin-arm64/flowcat
key: ${{ github.sha }}
- name: upload-linux-386-cache
id: linux-386-cache
uses: actions/cache/save@v3
with:
path: |
bin
bin/*
bin/flowcat-linux-386/flowcat
key: ${{ github.sha }}
- name: upload-linux-amd64-cache
id: linux-amd64-cache
uses: actions/cache/save@v3
with:
path: |
bin
bin/*
bin/flowcat-linux-amd64/flowcat
key: ${{ github.sha }}
release:
name: "Release"
needs: [build]
runs-on: "ubuntu-latest"
steps:
- name: get-cache-key
env:
cache_key: test
run: echo "$cache_key"
- name: get-cache
uses: actions/cache/restore@v3
with:
path: |
bin
bin/*
bin/flowcat-darwin-arm64/flowcat
key: ${{ github.sha }}
#key: test
- name: "Determine tag"
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: "Create release"
uses: "actions/github-script@v6"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
try {
const response = await github.rest.repos.createRelease({
draft: true,
generate_release_notes: true,
name: process.env.RELEASE_TAG,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
});
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: response.data.id,
name: "flowcat-darwin-arm64",
data: await fs.readFileSync("bin/flowcat-darwin-arm64/flowcat")
});
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: response.data.id,
name: "flowcat-linux-386",
data: await fs.readFileSync("bin/flowcat-linux-386/flowcat")
});
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: response.data.id,
name: "flowcat-linux-amd64",
data: await fs.readFileSync("bin/flowcat-linux-amd64/flowcat")
});
core.exportVariable('RELEASE_ID', response.data.id);
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}