-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (97 loc) · 4.17 KB
/
publish.yml
File metadata and controls
112 lines (97 loc) · 4.17 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
name: Publish Release
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for the release'
required: true
title:
description: 'Title of the release'
required: true
description:
description: 'Path to the markdown file for release description'
default: 'release_descriptions/?.md'
required: true
permissions:
contents: write # Ensures the GITHUB_TOKEN can create releases
jobs:
create-github-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Read Release Description from Markdown File
run: |
if [ -f "${{ github.event.inputs.description }}" ]; then
description=$(<"${{ github.event.inputs.description }}")
else
description="No description provided."
fi
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
echo "$description" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DESCRIPTION: ${{ env.DESCRIPTION }}
run: |
tag="${{ github.event.inputs.tag }}"
title="${{ github.event.inputs.title }}"
description="$DESCRIPTION"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg tag "$tag" --arg title "$title" --arg description "$description" \
'{tag_name: $tag, target_commitish: "main", name: $title, body: $description, draft: false, prerelease: false}')" \
https://api.github.com/repos/JEMcats-Software/WebGlass/releases --output release.json
upload_url=$(jq -r '.upload_url' release.json | sed "s/{?name,label}//")
echo "UPLOAD_URL=$upload_url" >> $GITHUB_ENV
- name: Upload WebGlass.js to Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
TITLE: ${{ github.event.inputs.title }}
run: |
upload_url="${UPLOAD_URL}?name=WebGlass-${TITLE}.js"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @WebGlass.js \
"$upload_url"
upload-to-s3:
runs-on: ubuntu-latest
needs: create-github-release # Ensure this runs after the release is created
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: main # Checkout the 'main' branch
# Install AWS CLI
- name: Install AWS CLI
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv3.zip"
unzip awscliv3.zip
sudo ./aws/install --update
aws --version # Verify installation
# Configure AWS credentials
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
# Minify JavaScript
- name: Minify JavaScript
run: |
npm install -g terser
terser WebGlass.js -o WebGlass.min.js --compress --mangle
# Sync contents to S3 bucket while excluding .github folder
- name: Sync to S3
run: |
aws s3 cp WebGlass.js s3://cdn.jemcats.software/WebGlass/${{ github.event.inputs.tag }}/WebGlass.js --content-type "text/javascript"
aws s3 cp WebGlass.min.js s3://cdn.jemcats.software/WebGlass/${{ github.event.inputs.tag }}/WebGlass.min.js --content-type "text/javascript"
aws s3 cp demo/ s3://jemcats.software/github_pages/WebGlass/ --recursive
- name: Clear and Publish Latest to S3
run: |
aws s3 rm s3://cdn.jemcats.software/WebGlass/latest/ --recursive
aws s3 cp s3://cdn.jemcats.software/WebGlass/${{ github.event.inputs.tag }}/ s3://cdn.jemcats.software/WebGlass/latest/ --recursive --content-type "text/javascript" --exclude "*" --include "*.js"