Skip to content

Commit 25d877b

Browse files
authored
ci: add build and release workflow
1 parent ed2beb8 commit 25d877b

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
workflow_dispatch:
9+
inputs:
10+
publish:
11+
description: 'Create Production Release'
12+
required: true
13+
type: boolean
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Get Next Version
25+
if: ${{ github.event.inputs.publish }}
26+
id: semver
27+
uses: ietf-tools/semver-action@v1
28+
with:
29+
token: ${{ github.token }}
30+
branch: main
31+
32+
- name: Set Next Version Env Var
33+
if: ${{ github.event.inputs.publish }}
34+
env:
35+
NEXT_VERSION: ${{ steps.semver.outputs.next }}
36+
run: |
37+
echo "NEXT_VERSION=$next" >> $GITHUB_ENV
38+
39+
- name: Create Draft Release
40+
uses: ncipollo/release-action@v1
41+
if: ${{ github.event.inputs.publish }}
42+
with:
43+
prerelease: true
44+
draft: false
45+
commit: ${{ github.sha }}
46+
tag: ${{ env.NEXT_VERSION }}
47+
name: ${{ env.NEXT_VERSION }}
48+
body: '*pending*'
49+
token: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Set Build Variables
52+
run: |
53+
if [[ $NEXT_VERSION ]]; then
54+
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
55+
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
56+
echo "PKG_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
57+
echo "PKG_VERSION_STRICT=${NEXT_VERSION#?}" >> $GITHUB_ENV
58+
elif [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
59+
echo "Using TAG mode: $GITHUB_REF_NAME"
60+
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
61+
echo "PKG_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
62+
echo "PKG_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
63+
else
64+
echo "Using TEST mode: v7.0.0-dev.$GITHUB_RUN_NUMBER"
65+
echo "SHOULD_DEPLOY=false" >> $GITHUB_ENV
66+
echo "PKG_VERSION=v3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
67+
echo "PKG_VERSION_STRICT=3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
68+
fi
69+
70+
- name: Setup Node.js
71+
uses: actions/setup-node@v3.0.0
72+
with:
73+
node-version: 16.x
74+
75+
- name: Setup Python
76+
uses: actions/setup-python@v2
77+
with:
78+
python-version: '3.x'
79+
80+
- name: Make Release Build
81+
env:
82+
DEBIAN_FRONTEND: noninteractive
83+
run: |
84+
npm install
85+
echo "Using version $PKG_VERSION_STRICT"
86+
sed -i -r -e "s/^__version__ += '.*'$/__version__ = '$PKG_VERSION_STRICT'/" ietf/__init__.py
87+
tar -czf release.tar.gz -X dev/deploy/exclude-patterns.txt .
88+
89+
- name: Update CHANGELOG
90+
id: changelog
91+
uses: Requarks/changelog-action@v1
92+
if: env.SHOULD_DEPLOY == 'true'
93+
with:
94+
token: ${{ github.token }}
95+
tag: ${{ env.PKG_VERSION }}
96+
writeToFile: false
97+
98+
- name: Create Release
99+
uses: ncipollo/release-action@v1
100+
if: env.SHOULD_DEPLOY == 'true'
101+
with:
102+
allowUpdates: true
103+
draft: false
104+
tag: ${{ env.PKG_VERSION }}
105+
name: ${{ env.PKG_VERSION }}
106+
body: ${{ steps.changelog.outputs.changes }}
107+
artifacts: "release.tar.gz"
108+
token: ${{ secrets.GITHUB_TOKEN }}
109+
110+
- name: Upload Build Artifacts
111+
uses: actions/upload-artifact@v2.3.1
112+
if: env.SHOULD_DEPLOY == 'false'
113+
with:
114+
name: artifacts
115+
path: |
116+
release.tar.gz

0 commit comments

Comments
 (0)