forked from reallyreally/docker-snmpd
-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (53 loc) · 2.64 KB
/
build-and-push.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
name: Build and Push Docker Image
on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight
workflow_dispatch: # Allows manual trigger
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest snmpd version
id: get-version
run: |
latest_version=$(curl -s "https://sourceforge.net/projects/net-snmp/files/net-snmp/" | grep -Po 'href="\/projects\/net-snmp\/files\/net-snmp\/\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -1)
echo "latest_version=${latest_version}" >> $GITHUB_ENV
major_version=$(echo $latest_version | cut -d'.' -f1)
minor_version=$(echo $latest_version | cut -d'.' -f1-2)
echo "major_version=${major_version}" >> $GITHUB_ENV
echo "minor_version=${minor_version}" >> $GITHUB_ENV
- name: Build Docker image
run: |
repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker build --build-arg SNMPD_VERSION=${{ env.latest_version }} -t ghcr.io/$repo_name/snmpd:${{ env.latest_version }} .
- name: Tag Docker image
run: |
repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:latest
docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:${{ env.major_version }}
docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:${{ env.minor_version }}
- name: Push Docker image
run: |
repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker push ghcr.io/$repo_name/snmpd:${{ env.latest_version }}
docker push ghcr.io/$repo_name/snmpd:latest
docker push ghcr.io/$repo_name/snmpd:${{ env.major_version }}
docker push ghcr.io/$repo_name/snmpd:${{ env.minor_version }}
- name: Tag the repository with the latest version
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag ${latest_version}
git push origin ${latest_version}