-
Notifications
You must be signed in to change notification settings - Fork 1
115 lines (97 loc) · 3.42 KB
/
deploy.yml
File metadata and controls
115 lines (97 loc) · 3.42 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
name: Deploy
on:
push:
branches:
- 'main'
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
jobs:
build:
runs-on: ubuntu-latest
env:
CI: true
DISABLE_NOTIFIER: true
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Delete the postinstall script
# Otherwise it enter the watch task and never finishes
run: npm pkg delete scripts.postinstall
- name: Install dependencies
run: npm ci --no-audit --fund=false
- name: Compile CSS
run: npm run styles
- name: Compile JavaScript
run: npm run scripts
- name: Configure git
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}+github-actions[bot]@users.noreply.github.com"
- name: Commit changes
run: |
rm .gitignore
mv .gitignore-build .gitignore
git add -A
git commit -m "Build"
# Setup variables
BUILD_BRANCH="${GITHUB_REF_NAME}-build"
GITHUB_ACTION_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}/checks"
# Switch branches... maybe?
git fetch --all
if [ ! `git branch -r --list origin/$BUILD_BRANCH` ]; then
# Branch doesn't exist. Create it and check it out.
git checkout --orphan ${BUILD_BRANCH}
git rm -rf .
git commit --allow-empty -m "Initial Commit"
else
git checkout -f ${BUILD_BRANCH}
fi
# Capture diff of the changes between the two branches
git diff --no-color --binary --full-index ${BUILD_BRANCH} ${GITHUB_REF_NAME} > ~/${BUILD_BRANCH}.diff
# If the diff file is not empty then continue
if [ -s ~/${BUILD_BRANCH}.diff ]; then
# Apply changes to the build branch
git apply --index ~/${BUILD_BRANCH}.diff
# Add file changes and commit
git add .
git commit -m "Merged ${GITHUB_SHA} from ${GITHUB_REF_NAME}" -m "${GITHUB_ACTION_URL}"
git push origin ${BUILD_BRANCH} --force
else
echo "Nothing changed. No commit."
fi
# - name: Configure SSH
# if: ${{ github.ref == 'refs/heads/master' }}
# run: |
# mkdir -p ~/.ssh/
# echo "$SSH_KEY" > ~/.ssh/staging.key
# chmod 600 ~/.ssh/staging.key
# cat >>~/.ssh/config <<END
# Host staging
# HostName $SSH_HOST
# Port 22
# User $SSH_USER
# IdentityFile ~/.ssh/staging.key
# ForwardAgent yes
# StrictHostKeyChecking no
# END
# env:
# SSH_USER: ${{ secrets.SSH_USER }}
# SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
# SSH_HOST: ${{ secrets.SSH_HOST }}
# - name: Deploy
# if: github.ref == 'refs/heads/master'
# run: ssh -T staging
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}