|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * 0' # Runs every Sunday at midnight |
| 6 | + workflow_dispatch: # Allows manual trigger |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-push: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - name: Set up QEMU |
| 17 | + uses: docker/setup-qemu-action@v2 |
| 18 | + |
| 19 | + - name: Set up Docker Buildx |
| 20 | + uses: docker/setup-buildx-action@v2 |
| 21 | + |
| 22 | + - name: Login to GitHub Container Registry |
| 23 | + uses: docker/login-action@v2 |
| 24 | + with: |
| 25 | + registry: ghcr.io |
| 26 | + username: ${{ github.repository_owner }} |
| 27 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Get latest snmpd version |
| 30 | + id: get-version |
| 31 | + run: | |
| 32 | + 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) |
| 33 | + echo "latest_version=${latest_version}" >> $GITHUB_ENV |
| 34 | + major_version=$(echo $latest_version | cut -d'.' -f1) |
| 35 | + minor_version=$(echo $latest_version | cut -d'.' -f1-2) |
| 36 | + echo "major_version=${major_version}" >> $GITHUB_ENV |
| 37 | + echo "minor_version=${minor_version}" >> $GITHUB_ENV |
| 38 | +
|
| 39 | + - name: Build Docker image |
| 40 | + run: | |
| 41 | + repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') |
| 42 | + docker build --build-arg SNMPD_VERSION=${{ env.latest_version }} -t ghcr.io/$repo_name/snmpd:${{ env.latest_version }} . |
| 43 | +
|
| 44 | + - name: Tag Docker image |
| 45 | + run: | |
| 46 | + repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') |
| 47 | + docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:latest |
| 48 | + docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:${{ env.major_version }} |
| 49 | + docker tag ghcr.io/$repo_name/snmpd:${{ env.latest_version }} ghcr.io/$repo_name/snmpd:${{ env.minor_version }} |
| 50 | +
|
| 51 | + - name: Push Docker image |
| 52 | + run: | |
| 53 | + repo_name=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') |
| 54 | + docker push ghcr.io/$repo_name/snmpd:${{ env.latest_version }} |
| 55 | + docker push ghcr.io/$repo_name/snmpd:latest |
| 56 | + docker push ghcr.io/$repo_name/snmpd:${{ env.major_version }} |
| 57 | + docker push ghcr.io/$repo_name/snmpd:${{ env.minor_version }} |
| 58 | +
|
| 59 | + - name: Tag the repository with the latest version |
| 60 | + run: | |
| 61 | + git config --global user.name "github-actions[bot]" |
| 62 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 63 | + git tag ${latest_version} |
| 64 | + git push origin ${latest_version} |
0 commit comments