-
-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (88 loc) · 2.75 KB
/
release.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
name: Release
on:
push:
tags:
- "v*"
workflow_run:
workflows:
- Tagging
types:
- completed
branches:
- main
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Fetch remote tags
run: git fetch origin +refs/tags/*:refs/tags/*
- name: Set Tag Value
run: |
export DATE=v$(echo `date +'%Y.%m'`)
echo "DATE=${DATE}" >> $GITHUB_ENV
echo "TAG=$(echo `git tag -l ${DATE}`)" >> $GITHUB_ENV
- name: Create Release
uses: actions/github-script@v6
id: release
if: ${{ env.TAG }}
with:
github-token: ${{ github.token }}
result-encoding: string
script: |
const { repo: { owner, repo }, sha } = context;
const tag = process.env.DATE;
let release_id = 0;
try {
const release = await github.rest.repos.createRelease({
owner, repo,
tag_name: tag,
title: tag,
release_name: tag,
draft: false,
target_commitish: sha
});
release_id = release.data.id;
} catch (e) {
let latest;
if (e.status == 422) { // Release alredy exists
latest = await github.rest.repos.getLatestRelease({
owner, repo
});
}
release_id = latest.data.id;
}
return release_id
- name: Upload Release Assets
uses: actions/github-script@v6
if: ${{ steps.release.outputs.result }}
with:
github-token: ${{ github.token }}
script: |
const { repo: { owner, repo }, sha } = context;
const fs = require('fs').promises;
try {
let asset_ids = await github.rest.repos.listReleaseAssets({
owner, repo,
release_id: ${{ steps.release.outputs.result }}
})
for (let asset of asset_ids.data) {
await github.rest.repos.deleteReleaseAsset({
owner, repo,
asset_id: asset.id
});
}
} catch (e) {
console.log(e.status);
} finally {
for (let file of await fs.readdir('./deployment')) {
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: ${{ steps.release.outputs.result }},
name: file,
data: await fs.readFile(`./deployment/${file}`)
})
}
}