Skip to content

Commit eaa18e9

Browse files
authored
Merge pull request #30 from philwhineray/master
Replace Travis with Github actions
2 parents 71a3075 + adcc1cd commit eaa18e9

File tree

7 files changed

+174
-119
lines changed

7 files changed

+174
-119
lines changed

.github/workflows/publish.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
on: [ push, pull_request, workflow_dispatch ]
2+
3+
jobs:
4+
prep:
5+
runs-on: ubuntu-latest
6+
name: Prepare build
7+
steps:
8+
- name: Extract tag/branch variables
9+
shell: bash
10+
run: |
11+
echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/}|grep -v '/')"
12+
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/}|grep -v '/')"
13+
id: extract
14+
outputs:
15+
tag: ${{ steps.extract.outputs.tag }}
16+
branch: ${{ steps.extract.outputs.branch }}
17+
18+
build:
19+
runs-on: ubuntu-latest
20+
name: Build package
21+
needs: prep
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set up build tools
25+
run: ./.github/workflows/setup.sh
26+
- name: Server-side run of commit hooks in case developer skipped them
27+
run: git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ./packaging/check-files -
28+
env:
29+
TRAVIS_TAG: ${{ needs.prep.outputs.tag }}
30+
- name: Obtain GPG keys to validate tag signature
31+
if: ${{ needs.prep.outputs.tag != '' }}
32+
run: |
33+
./packaging/gpg-recv-key [email protected] "0762 9FF7 89EA 6156 012F 9F50 C406 9602 1359 9237"
34+
./packaging/gpg-recv-key [email protected] "4DFF 624A E564 3B51 2872 1F40 29CA 3358 89B9 A863"
35+
git fetch --tags -f
36+
env:
37+
KEYSERVER: pool.sks-keyservers.net
38+
- name: Run build
39+
run: fakeroot ./packaging/git-build && ./configure && make check
40+
env:
41+
TRAVIS_TAG: ${{ needs.prep.outputs.tag }}
42+
- name: Create checksums
43+
run: |
44+
for i in *.tar.*
45+
do
46+
md5sum -b $i > $i.md5
47+
sha512sum -b $i > $i.sha
48+
done
49+
- name: Upload build artifacts
50+
uses: actions/upload-artifact@v2
51+
with:
52+
name: build-artifacts
53+
path: |
54+
*.tar.*
55+
56+
publish_branch:
57+
runs-on: ubuntu-latest
58+
name: Publish to website if branch
59+
needs: [ prep, build ]
60+
env:
61+
DEPLOY_ARTIFACTS: "*.tar.*"
62+
DEPLOY_SERVER: [email protected]
63+
DEPLOY_DIR: uploads/iprange/${{needs.prep.outputs.branch}}
64+
SERVER_DEPLOY_LOG: https://firehol.org/travis-project.log
65+
SERVER_DEPLOY_TIMEOUT: 300
66+
if: >-
67+
${{ ( needs.prep.outputs.branch == 'main'
68+
|| needs.prep.outputs.branch == 'master'
69+
|| startsWith( needs.prep.outputs.branch, 'stable-' ) ) }}
70+
steps:
71+
- name: Download artifacts
72+
uses: actions/download-artifact@v2
73+
with:
74+
name: build-artifacts
75+
- name: Setup SSH
76+
id: ssh
77+
run: |
78+
echo "$FIREHOL_ORG_PUBLISH_SSH" > firehol_org_publish_key
79+
chmod 600 firehol_org_publish_key
80+
eval "$(ssh-agent)"
81+
if ssh-add firehol_org_publish_key; then
82+
echo "Key added: setting agent environment"
83+
echo "##[set-output name=ssh_agent_pid;]$SSH_AGENT_PID"
84+
echo "##[set-output name=ssh_auth_sock;]$SSH_AUTH_SOCK"
85+
mkdir -p $HOME/.ssh
86+
chmod 700 $HOME/.ssh
87+
echo PasswordAuthentication=no >> $HOME/.ssh/config
88+
chmod 644 $HOME/.ssh/config
89+
else
90+
echo "Key not added: skipping ssh-agent environment"
91+
fi
92+
rm -f firehol_org_publish_key
93+
env:
94+
FIREHOL_ORG_PUBLISH_SSH: ${{secrets.FIREHOL_ORG_PUBLISH_SSH}}
95+
- name: Prepare deployment check
96+
if: ${{ steps.ssh.outputs.ssh_agent_pid != '' }}
97+
run: curl -s -oresult.orig $SERVER_DEPLOY_LOG
98+
- name: Deploy to website ${{needs.prep.outputs.branch}}
99+
if: ${{ steps.ssh.outputs.ssh_agent_pid != '' }}
100+
run: |
101+
ssh-keyscan -H firehol.org >> ~/.ssh/known_hosts
102+
ssh $DEPLOY_SERVER mkdir -p "$DEPLOY_DIR"
103+
rsync -a $DEPLOY_ARTIFACTS "$DEPLOY_SERVER:$DEPLOY_DIR/"
104+
ssh $DEPLOY_SERVER touch "$DEPLOY_DIR/complete.txt"
105+
env:
106+
SSH_AGENT_PID: ${{ steps.ssh.outputs.ssh_agent_pid }}
107+
SSH_AUTH_SOCK: ${{ steps.ssh.outputs.ssh_auth_sock }}
108+
- name: Check deployment
109+
if: ${{ steps.ssh.outputs.ssh_agent_pid != '' }}
110+
run: |
111+
pause=10
112+
attempts=$(( $SERVER_DEPLOY_TIMEOUT / $pause ))
113+
while [ $attempts -gt 0 ]
114+
do
115+
sleep $pause
116+
attempts=$((attempts - 1))
117+
curl -s -o result $SERVER_DEPLOY_LOG
118+
if ! cmp -s result result.orig
119+
then
120+
cat result
121+
if grep -q "not deploying" result
122+
then
123+
exit 2
124+
else
125+
exit 0
126+
fi
127+
fi
128+
done
129+
exit 1
130+
131+
publish_tag:
132+
runs-on: ubuntu-latest
133+
name: Publish to github if tag
134+
needs: [ prep, build ]
135+
if: ${{ needs.prep.outputs.tag != '' }}
136+
steps:
137+
- name: Download artifacts
138+
uses: actions/download-artifact@v2
139+
with:
140+
name: build-artifacts
141+
- name: Create Release
142+
id: create_release
143+
uses: actions/create-release@v1
144+
env:
145+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146+
with:
147+
tag_name: ${{ github.ref }}
148+
release_name: Release ${{ github.ref }}
149+
draft: true
150+
- name: Upload
151+
uses: actions/github-script@v3
152+
with:
153+
github-token: ${{secrets.GITHUB_TOKEN}}
154+
script: |
155+
const path = require('path');
156+
const fs = require('fs');
157+
const release_id = '${{ steps.create_release.outputs.id }}';
158+
for (let file of await fs.readdirSync('./')) {
159+
console.log('uploadReleaseAsset', file);
160+
await github.repos.uploadReleaseAsset({
161+
owner: context.repo.owner,
162+
repo: context.repo.repo,
163+
release_id: release_id,
164+
name: file,
165+
data: await fs.readFileSync(`./${file}`)
166+
});
167+
}

.github/workflows/setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -e
4+
set -x
5+
6+
sudo apt install gnupg help2man fakeroot

.travis.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.travis/decrypt-if-have-key

Lines changed: 0 additions & 33 deletions
This file was deleted.

.travis/deploy-if-have-key

Lines changed: 0 additions & 39 deletions
This file was deleted.

.travis/travis_rsa.enc

-1.64 KB
Binary file not shown.

packaging/tar-compare

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ diff -r "$1" $MYTMP/unpack/* | grep "^Only" | sed \
4040
-e '/: \.git$/d' \
4141
-e '/: \.gitattributes$/d' \
4242
-e '/: \.gitignore$/d' \
43+
-e '/: \.github$/d' \
4344
-e '/: \.travis$/d' \
4445
-e '/: \.travis.yml$/d' \
4546
-e '/: config\.log$/d' \

0 commit comments

Comments
 (0)