• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1module.exports = async ({github, context, core}) => {
2    try {
3	await github.rest.git.updateRef({
4	    owner: context.repo.owner,
5	    repo: context.repo.repo,
6	    ref: 'tags/master-tot',
7	    sha: context.sha
8	})
9    } catch (error) {
10	core.setFailed(`upload master-tot tag; ${error.name}; ${error.message}`)
11    }
12
13    let release
14    try {
15	release = await github.rest.repos.getReleaseByTag({
16	    owner: context.repo.owner,
17	    repo: context.repo.repo,
18	    tag: 'master-tot'
19	})
20    } catch (error) {
21	core.setFailed(`get the master release; ${error.name}; ${error.message}`)
22    }
23
24    try {
25	await github.rest.repos.updateRelease({
26	    owner: context.repo.owner,
27	    repo: context.repo.repo,
28	    release_id: release.data.id
29	})
30    } catch (error) {
31	core.setFailed(`update the master release; ${error.name}; ${error.message}`)
32    }
33
34    let release_assets
35    try {
36	release_assets = await github.rest.repos.listReleaseAssets({
37	    owner: context.repo.owner,
38	    repo: context.repo.repo,
39	    release_id: release.data.id
40	})
41    } catch (error) {
42	core.setFailed(`list release assets; ${error.name}; ${error.message}`)
43    }
44
45    const { ARCHIVE } = process.env
46    for (const release_asset of release_assets.data) {
47	if (release_asset.name === `${ ARCHIVE }`) {
48	    try {
49		await github.rest.repos.deleteReleaseAsset({
50		    owner: context.repo.owner,
51		    repo: context.repo.repo,
52		    asset_id: release_asset.id
53		})
54	    } catch (error) {
55		core.setFailed(`delete ${ ARCHIVE }; ${error.name}; ${error.message}`)
56	    }
57	}
58    }
59
60    try {
61	const asset_path = `./build/install/${ ARCHIVE }`
62	const fs = require("fs")
63	await github.rest.repos.uploadReleaseAsset({
64	    owner: context.repo.owner,
65	    repo: context.repo.repo,
66	    release_id: release.data.id,
67	    name: `${ ARCHIVE }`,
68	    data: fs.readFileSync(asset_path)
69	})
70    } catch (error) {
71	core.setFailed(`upload ${ ARCHIVE }; ${error.name}; ${error.message}`)
72    }
73}
74