-
-
Notifications
You must be signed in to change notification settings - Fork 4
116 lines (100 loc) · 4.02 KB
/
Copy pathgenerate-license.yml
File metadata and controls
116 lines (100 loc) · 4.02 KB
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
name: Generate and Verify License
# Include the unique GitHub run number both in the run name and passed to the script as the license number
run-name: "License #${{ github.run_number }}"
on:
workflow_dispatch:
inputs:
name:
description: 'Name'
required: false
default: 'Trial User'
email:
description: 'Email'
required: false
default: 'trial@lighthouse.com'
organization:
description: 'Organization'
required: false
default: 'Trial Organization'
expiry:
description: 'Expiry Date (YYYY-MM-DD) - defaults to 2 weeks from now'
required: false
valid_from:
description: 'Valid From Date (YYYY-MM-DD) - defaults to today'
required: false
jobs:
generate-and-verify:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97
with:
python-version: '3.10'
- name: Set default expiry date (2 weeks from now)
id: set-expiry
run: |
if [ -z "${{ github.event.inputs.expiry }}" ]; then
EXPIRY_DATE=$(date -d "+14 days" +%Y-%m-%d)
else
EXPIRY_DATE="${{ github.event.inputs.expiry }}"
fi
echo "expiry_date=$EXPIRY_DATE" >> $GITHUB_OUTPUT
- name: Set default valid from date (today)
id: set-valid-from
run: |
if [ -z "${{ github.event.inputs.valid_from }}" ]; then
VALID_FROM_DATE=$(date +%Y-%m-%d)
else
VALID_FROM_DATE="${{ github.event.inputs.valid_from }}"
fi
echo "valid_from_date=$VALID_FROM_DATE" >> $GITHUB_OUTPUT
- name: Set default values
id: set-defaults
run: |
NAME="${{ github.event.inputs.name }}"
EMAIL="${{ github.event.inputs.email }}"
ORG="${{ github.event.inputs.organization }}"
if [ -z "$NAME" ]; then
NAME="Trial User"
fi
if [ -z "$EMAIL" ]; then
EMAIL="trial@lighthouse.com"
fi
if [ -z "$ORG" ]; then
ORG="Trial Organization"
fi
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "email=$EMAIL" >> $GITHUB_OUTPUT
echo "organization=$ORG" >> $GITHUB_OUTPUT
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install cryptography
- name: Write private key to file
run: echo "${{ secrets.LIGHTHOUSE_LICENSE_PRIVATE_KEY }}" > private_key.pem
- name: Generate license
run: |
python Scripts/generate_license.py private_key.pem license.json "${{ github.run_number }}" "${{ steps.set-defaults.outputs.name }}" "${{ steps.set-defaults.outputs.email }}" "${{ steps.set-defaults.outputs.organization }}" "${{ steps.set-expiry.outputs.expiry_date }}" "${{ steps.set-valid-from.outputs.valid_from_date }}"
- name: Write public key to file
run: echo "${{ secrets.LIGHTHOUSE_LICENSE_PUBLIC_KEY }}" > public_key.pem
- name: Verify license
run: python Scripts/verify_license.py public_key.pem license.json
- name: Create license zip file
run: |
zip lighthouse-license.zip license.json
ls -la lighthouse-license.zip
- name: Upload license as artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: license
path: lighthouse-license.zip
- name: Send license via email
run: python Scripts/send_license_email.py
env:
MAILGUN_SMTP_USERNAME: ${{ secrets.MAILGUN_SMTP_USERNAME }}
MAILGUN_SMTP_PASSWORD: ${{ secrets.MAILGUN_SMTP_PASSWORD }}
RECIPIENT_NAME: ${{ steps.set-defaults.outputs.name }}
RECIPIENT_EMAIL: ${{ steps.set-defaults.outputs.email }}
ORGANIZATION: ${{ steps.set-defaults.outputs.organization }}