-
Notifications
You must be signed in to change notification settings - Fork 24
153 lines (148 loc) · 6.07 KB
/
ci.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: CI
on:
push:
branches:
- master
- develop
pull_request:
jobs:
build:
runs-on: ubuntu-latest
container: pc2fromecs/jdk8hugo
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16.20.x
cache: npm
cache-dependency-path: projects/WTI-UI/package.json
- name: Build
run: ant -noinput -buildfile package.xml
- uses: actions/upload-artifact@v3
with:
name: build
path: dist/*
push-release:
runs-on: ubuntu-latest
container: pc2fromecs/jdk8hugo
needs: build
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: build
path: dist
- name: Create GitHub release
shell: bash
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
eval $(ssh-agent -s)
echo "${{ secrets.SSH_PRIVATE_KEY_WEBSITE }}" | tr -d '\r' | ssh-add -
mkdir -p ~/.ssh
chmod 700 ~/.ssh
export GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no'
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
git config --global user.email "[email protected]"
git config --global user.name "PC2 bot"
export VERSION=`echo dist/pc2-*.zip | sed 's#^dist.*pc2-\(.*\).zip*#\1#'`
export VERSION1=`echo dist/pc2-*.zip | sed 's#^dist.*pc2-\(.*\).zip*#\1#' | sed 's/~.*//'`
if ( test "$GITHUB_REF" = 'refs/heads/master' ); then
TARGET=builds
else
TARGET=nightly-builds
fi
cur_dir=`pwd`
mkdir ~/builds
cd ~/builds
git clone [email protected]:${GITHUB_REPOSITORY_OWNER}/${TARGET}.git .
# a commit is needed to associate to a release
git commit --allow-empty -m "Add build $VERSION"
git push
RELEASE_COMMIT=$(git rev-parse HEAD)
cd "$cur_dir"
curl --silent --show-error --retry 6 --retry-all-errors --max-time 300 -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY_OWNER}/${TARGET}/releases \
-d '{"tag_name":"'"v$VERSION1"'", "name":"'"v$VERSION"'", "prerelease": true, "target_commitish": "'"$RELEASE_COMMIT"'" }' | \
tee ~/new-release.txt
RELEASE_ASSET_UPLOAD_URL=$(cat ~/new-release.txt | jq .upload_url | sed -e 's/"//g' -e 's#/assets{.*#/assets#' )
cd dist
echo "Uploading release $VERSION using URL $RELEASE_ASSET_UPLOAD_URL"
for archive in *.zip *.gz
do
echo $archive...
case "$archive" in
*.zip)
curl --silent --show-error --retry 6 --retry-all-errors --max-time 300 --data-binary "@$archive" -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Content-Type: application/zip' \
${RELEASE_ASSET_UPLOAD_URL}\?name=$archive \
| jq .state
;;
*.tar.gz)
curl --silent --show-error --retry 6 --retry-all-errors --max-time 300 --data-binary "@$archive" -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Content-Type: application/gzip' \
${RELEASE_ASSET_UPLOAD_URL}\?name=$archive \
| jq .state
;;
esac
if [ -f $archive.sha256.txt ]; then
echo $archive.sha256.txt...
curl --silent --show-error --retry 6 --retry-all-errors --max-time 300 --data-binary "@$archive.sha256.txt" -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Content-Type: text/plain' \
${RELEASE_ASSET_UPLOAD_URL}\?name=$archive.sha256.txt \
| jq .state
fi
if [ -f $archive.sha512.txt ]; then
echo $archive.sha512.txt...
curl --silent --show-error --retry 6 --retry-all-errors --max-time 300 --data-binary "@$archive.sha512.txt" -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Content-Type: text/plain' \
${RELEASE_ASSET_UPLOAD_URL}\?name=$archive.sha512.txt \
| jq .state
fi
done
update-website:
runs-on: ubuntu-latest
container: pc2fromecs/jdk8hugo
needs: push-release
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build
path: dist
- name: Push release to website
shell: bash
run: |
eval $(ssh-agent -s)
echo "${{ secrets.SSH_PRIVATE_KEY_WEBSITE }}" | tr -d '\r' | ssh-add -
mkdir -p ~/.ssh
chmod 700 ~/.ssh
export GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=no'
git config --global user.email "[email protected]"
git config --global user.name "PC2 bot"
website/scripts/populate-releases.py ${{ secrets.RELEASE_TOKEN }}
mkdir ~/website
git clone [email protected]:pc2ccs/pc2ccs.github.io.git ~/website
ln -s ~/website website/public
cd website
hugo
cd ~/website
git add .
git commit --allow-empty -m "Update website for pc2v9 commit $GITHUB_SHA"
git push