-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (88 loc) · 4.08 KB
/
joplin.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
name: Joplin Server
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
env:
DOCKER_REPO: ataraxiadev/joplin-server
LATEST_TAG: ataraxiadev/joplin-server:latest
UPSTREAM: laurent22/joplin
jobs:
check:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Get latest release tag and hash
id: tags
run: |
RELEASE_TAG=$(curl -s GET "https://api.github.com/repos/${{ env.UPSTREAM }}/releases?per_page=40" | jq -er "[.[]|select(.prerelease==false)][0].tag_name")
RELEASE_SHA=$(curl -s GET "https://api.github.com/repos/${{ env.UPSTREAM }}/tags?per_page=40" | jq -er "[.[]|select(.name==\"$RELEASE_TAG\")][0].commit.sha")
BETA_TAG=$(curl -s GET "https://api.github.com/repos/${{ env.UPSTREAM }}/releases?per_page=40" | jq -er "[.[]|select(.prerelease==true)][0].tag_name")
BETA_SHA=$(curl -s GET "https://api.github.com/repos/${{ env.UPSTREAM }}/tags?per_page=40" | jq -er "[.[]|select(.name==\"$BETA_TAG\")][0].commit.sha")
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
echo "release_sha=$RELEASE_SHA" >> $GITHUB_OUTPUT
echo "beta_tag=$BETA_TAG" >> $GITHUB_OUTPUT
echo "beta_sha=$BETA_SHA" >> $GITHUB_OUTPUT
- name: Check if tag already exists in docker repository
id: check
run: |
RELEASE_URL="https://hub.docker.com/v2/repositories/${{ env.DOCKER_REPO }}/tags/${{ steps.tags.outputs.release_tag }}"
BETA_URL="https://hub.docker.com/v2/repositories/${{ env.DOCKER_REPO }}/tags/${{ steps.tags.outputs.beta_tag }}"
[ $(curl -s GET $RELEASE_URL | jq .name) != "null" ] && echo "release_exists=true" >> $GITHUB_OUTPUT || echo "release_exists=false" >> $GITHUB_OUTPUT
[ $(curl -s GET $BETA_URL | jq .name) != "null" ] && echo "beta_exists=true" >> $GITHUB_OUTPUT || echo "beta_exists=false" >> $GITHUB_OUTPUT
- name: Generate matrix
id: matrix
run: |
json='{"include": []}'
if [ "${{ steps.check.outputs.release_exists }}" == "false" ]; then
json=$(echo $json | jq '.include+=[({"version":"release","tag":"${{ steps.tags.outputs.release_tag }}",sha:"${{ steps.tags.outputs.release_sha }}"})]')
fi
if [ "${{ steps.check.outputs.beta_exists }}" == "false" ]; then
json=$(echo $json | jq '.include+=[({"version":"beta","tag":"${{ steps.tags.outputs.beta_tag }}",sha:"${{ steps.tags.outputs.beta_sha }}"})]')
fi
echo "matrix=$(echo "$json" | jq -r '.include|tostring')" >> $GITHUB_OUTPUT
build:
needs: check
if: ${{ needs.check.outputs.matrix != '[]' }}
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
include: ${{ fromJson(needs.check.outputs.matrix) }}
steps:
- name: Checkout latest joplin release
uses: actions/checkout@v4
with:
repository: ${{ env.UPSTREAM }}
ref: ${{ matrix.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.server
load: true
tags: server:test
- name: Test docker image
run: docker run --rm server:test node dist/app.js migrate list
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.server
push: true
tags: |
${{ env.DOCKER_REPO }}:${{ matrix.tag }}${{ (matrix.version == 'beta') && '-beta' || '' }}
${{ (matrix.version == 'release') && env.LATEST_TAG || '' }}
build-args: |
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
REVISION=$(echo ${{ matrix.sha }} | cut -c1-8)
VERSION=${{ matrix.tag }}