-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (122 loc) · 5.68 KB
/
cron.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
name: cron
on:
push:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
validate:
runs-on: ubuntu-latest
outputs:
version_name: ${{ steps.set-version-name.outputs.version_name }}
is_new_version: ${{ steps.compare-versions.outputs.is_new_version }}
publish_version: ${{ steps.set-publish-version.outputs.publish_version }}
steps:
- name: Install depepndencies
run: sudo apt-get install -y curl jq
- name: Request current GitHub Synapse Package version
run: echo 'SYNAPSE_VERSION='$(curl -SsL https://api.github.com/repos/element-hq/synapse/releases | jq -r '.[].tag_name' | head -n 1) >> $GITHUB_ENV
- name: Request current Docker Hub Package version
run: echo 'DOCKER_VERSION='$(curl -sSL https://registry.hub.docker.com/v2/repositories/dotwee/matrix-synapse-s3/tags | jq -r '."results"[]["name"] | select(.=="'${{ env.SYNAPSE_VERSION }}'")') >> $GITHUB_ENV
- name: Overwrite versions if manually dispatched event
if: ${{ github.event.inputs.version_name != '' }}
run: |
echo 'SYNAPSE_VERSION=${{ github.event.inputs.version_name }}' >> $GITHUB_ENV
echo 'DOCKER_VERSION=""' >> $GITHUB_ENV
- name: Validate version-name is in format vXX.XX.XX
uses: actions-ecosystem/action-regex-match@v2
id: validate-version-name
with:
text: ${{ env.SYNAPSE_VERSION }}
regex: '^v\d+\.\d+\.\d+(?:rc\d+(?:\.\d)*)?$'
flags: gm
- name: Set & echo version name output
if: ${{ steps.validate-version-name.outputs.match == '' }}
run: |
echo "::error title=Invalid version_name format::The value ${{ env.SYNAPSE_VERSION }} is not a valid version_name value"
return -1
- name: Set & echo version name output
id: set-version-name
run: |
echo "SYNAPSE_VERSION=${{ env.SYNAPSE_VERSION }} DOCKER_VERSION=${{ env.DOCKER_VERSION }}"
echo "version_name=${{ env.SYNAPSE_VERSION }}" >> $GITHUB_OUTPUT
- name: Compare versions
id: compare-versions
run: echo "is_new_version=${{ env.SYNAPSE_VERSION != env.DOCKER_VERSION }}" >> $GITHUB_OUTPUT
- name: Set publish to false if manually triggered
id: set-publish-version
run: echo "publish_version=${{ github.event.inputs.version_name == '' }}" >> $GITHUB_OUTPUT
- name: Echo outputs
run: echo "version_name=${{ steps.set-version-name.outputs.version_name }} is_new_version=${{ steps.compare-versions.outputs.is_new_version }} publish_version=${{ steps.set-publish-version.outputs.publish_version }}"
release:
runs-on: ubuntu-latest
needs: validate
if: ${{ needs.validate.outputs.is_new_version == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GH_REGISTRY_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
dotwee/matrix-synapse-s3
ghcr.io/dotwee/matrix-synapse-s3
flavor: |
latest=${{ !(contains(needs.validate.outputs.version_name, 'rc')) }}
tags: |
type=raw,value=${{ needs.validate.outputs.version_name }}
type=raw,enable=${{ !(contains(needs.validate.outputs.version_name, 'rc')) }},value=stable
type=semver,pattern={{raw}},value=${{ needs.validate.outputs.version_name }}
labels: |
maintainer=Lukas Wolfsteiner <[email protected]>
org.opencontainers.image.title=matrix-synapse-s3
org.opencontainers.image.source="https://github.com/${{ github.repository }}"
- name: Build and push docker image with version tag
uses: docker/build-push-action@v6
id: docker-build
with:
platforms: linux/amd64,linux/arm64
build-args: |
SYNAPSE_VERSION=${{ needs.validate.outputs.version_name }}
SYNAPSE_S3_STORAGE_PROVIDER_COMMIT=main
push: ${{ needs.validate.outputs.publish_version == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Update Docker Hub repository description
uses: peter-evans/dockerhub-description@v4
if: ${{ needs.validate.outputs.publish_version == 'true' }}
with:
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
repository: dotwee/matrix-synapse-s3
- name: Create a GitHub repository release tag
uses: "marvinpinto/action-automatic-releases@latest"
if: ${{ needs.validate.outputs.publish_version == 'true' }}
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
title: ${{ needs.validate.outputs.version_name }}
prerelease: ${{ contains(needs.validate.outputs.version_name, 'rc') }}
automatic_release_tag: ${{ needs.validate.outputs.version_name }}