forked from JeDaYoshi/docker-nextdns
-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (116 loc) · 4.52 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
name: CI
on:
workflow_dispatch:
push:
branches:
- master
paths-ignore:
- "*.md"
- "LICENSE"
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
fetch:
name: Fetch latest NextDNS CLI release
runs-on: [self-hosted]
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0
- name: Fetch information from GitHub API
id: release
run: |
NEXTDNS_TAG=$(curl -svL https://api.github.com/repos/nextdns/nextdns/releases/latest | jq -r ".tag_name")
RELEASE_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) || true)
RELEASE_NUM=$(echo "$RELEASE_TAG" | rev | cut -d "-" -f1 | rev)
if [[ -z "$RELEASE_NUM" || "$RELEASE_NUM" = "$RELEASE_TAG" ]]; then
RELEASE_NUM="-1"
fi
if [[ "$(echo "$RELEASE_TAG" | rev | cut -d "-" -f2- | rev)" == "$NEXTDNS_TAG" ]]; then
exit 1
#RELEASE_NUM=$(echo "$RELEASE_NUM+1" | bc)
else
RELEASE_NUM="0"
fi
echo "::set-output name=nextdns_tag::$NEXTDNS_TAG"
echo "::set-output name=release_tag::$RELEASE_TAG"
echo "::set-output name=nextdns_ver::$(echo "$NEXTDNS_TAG" | sed "s/^v//")"
echo "::set-output name=docker_ver::$(echo "$RELEASE_TAG" | sed "s/^v//" | rev | cut -d "-" -f2- | rev)"
echo "::set-output name=release_new::$NEXTDNS_TAG-$RELEASE_NUM"
- name: Repo keep-alive
uses: gautamkrishnar/keepalive-workflow@master
continue-on-error: true
with:
commit_message: repo keepalive [ci skip]
committer_username: JeDa
committer_email: "[email protected]"
outputs:
nextdns_tag: ${{ steps.release.outputs.nextdns_tag }}
release_tag: ${{ steps.release.outputs.release_tag }}
nextdns_ver: ${{ steps.release.outputs.nextdns_ver }}
docker_ver: ${{ steps.release.outputs.docker_ver }}
release_new: ${{ steps.release.outputs.release_new }}
build:
name: Build Docker images
runs-on: ubuntu-latest
needs: fetch
if: needs.fetch.outputs.docker_ver != needs.fetch.outputs.nextdns_ver || github.ref == 'refs/heads/master'
env:
# This should be all the platforms both NextDNS and Alpine for Docker support in common.
ARCH_LIST: linux/amd64,linux/arm64,
steps:
- name: Set up QEMU
uses: docker/[email protected]
with:
platforms: ${{ env.ARCH_LIST }}
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
- name: Login to Docker Hub
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and export Docker image
uses: docker/[email protected]
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: |
NEXTDNS_VERSION=${{ needs.fetch.outputs.nextdns_ver }}
tags: ${{ env.IMAGE_NAME }}:latest
- name: Test Image
run: |
docker run --rm ${{ env.IMAGE_NAME }}:latest
- name: Push Docker image
uses: docker/[email protected]
with:
platforms: ${{ env.ARCH_LIST }}
push: true
builder: ${{ steps.buildx.outputs.name }}
build-args: |
NEXTDNS_VERSION=${{ needs.fetch.outputs.nextdns_ver }}
tags: ${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:${{ needs.fetch.outputs.nextdns_ver }}
tag:
name: Publish version tag
runs-on: [self-hosted]
needs: [fetch, build]
steps:
- name: Publish GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEXTDNS_TAG: ${{ needs.fetch.outputs.nextdns_tag }}
NEXTDNS_VER: ${{ needs.fetch.outputs.nextdns_ver }}
RELEASE_NEW: ${{ needs.fetch.outputs.release_new }}
with:
tag_name: ${{ env.RELEASE_NEW }}
release_name: ${{ env.RELEASE_NEW }}
body: |
This is an automated deployment of [NextDNS CLI ${{ env.NEXTDNS_TAG }}](https://github.com/nextdns/nextdns/releases/${{ env.NEXTDNS_TAG }}).
You should be able to fetch this image using Docker/podman.
```sh
docker pull ${{ env.IMAGE_NAME }}:latest # always up-to-date
docker pull ${{ env.IMAGE_NAME }}:${{ env.NEXTDNS_VER }} # stick to this NextDNS release
```