-
Notifications
You must be signed in to change notification settings - Fork 2
129 lines (109 loc) · 4.07 KB
/
docker-publish.yml
File metadata and controls
129 lines (109 loc) · 4.07 KB
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
name: custom-ftp-server build
on:
schedule:
- cron: "0 0 * * 0"
push:
branches:
- "**"
tags:
- "v*.*.*"
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- name: Run curl command to get latest version
id: curl_output
run: |
tag_name=$(date +"%y.%m.0")
# Remove the leading 'v' from tag_name
echo "latest_version=${tag_name#v}" >> $GITHUB_OUTPUT
- name: Display latest version
run: |
echo "Latest Version: ${{ steps.curl_output.outputs.latest_version }}"
- name: Read version from file
id: read_version
run: |
echo "version=$(cat version.txt)" >> $GITHUB_OUTPUT
- name: Display version from file
run: |
echo "Version from File: ${{ steps.read_version.outputs.version }}"
- name: Check if versions are different
id: check_versions
run: |
if [ "${{ steps.curl_output.outputs.latest_version }}" != "${{ steps.read_version.outputs.version }}" ]; then
echo "Versions are different, running Docker build..."
git checkout -b version-update-${{ github.run_number }}
echo "${{ steps.curl_output.outputs.latest_version }}" > version.txt
echo "build_docker=true" >> $GITHUB_OUTPUT
else
echo "Versions are the same, skipping Docker build."
echo "build_docker=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.check_versions.outputs.build_docker == 'true'
run: |
git add version.txt
git config --global user.email "github-actions-bot@freeops.dev"
git config --global user.name "GitHub Actions Bot"
git commit -m "Update version to ${{ steps.curl_output.outputs.latest_version }}"
git push origin version-update-${{ github.run_number }}
- name: Create pull request
if: steps.check_versions.outputs.build_docker == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Update version to ${{ steps.curl_output.outputs.latest_version }}`,
body: 'Automated pull request to update version.',
head: `version-update-${context.runNumber}`,
base: 'main'
});
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
haravich/custom-ftp-server
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule,pattern={{date 'YYYYMMDD'}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=main-,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}