Created
May 25, 2023 21:35
-
-
Save smoonlee/ef0c79bf3dabd921e81d2557bda2517a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Docker Image | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
update_docker_image: | |
name: Update Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Check Package Version | |
id: check_package | |
run: | | |
package_name="github-docker" | |
response=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.PatToken }}" "https://api.github.com/user/packages/container/$package_name/versions" | jq '.[0]') | |
tag_version=$(echo "$response" | jq -r '.metadata.container.tags[0]') | |
# Parse the version parts | |
IFS='.' read -ra version_parts <<< "$tag_version" | |
major=${version_parts[0]} | |
minor=${version_parts[1]} | |
patch=${version_parts[2]} | |
# Increment the version | |
patch=$((patch + 1)) | |
next_version="${major}.${minor}.${patch}" | |
echo "NAME=$package_name" >> $GITHUB_ENV | |
echo "TAG_VERSION=$tag_version" >> $GITHUB_ENV | |
echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV | |
- name: Display Package Version Details | |
run: | | |
echo "Package: ${{ env.NAME }}" | |
echo "Current Version: ${{ env.TAG_VERSION }}" | |
echo "Updated Version: ${{ env.NEXT_VERSION }}" | |
- name: Build and publish a Docker image for ${{ github.repository }} | |
uses: macbre/push-to-ghcr@master | |
with: | |
image_name: ${{ github.repository }} # it will be lowercased internally | |
github_token: ${{ secrets.PatToken }} | |
image_tag: ${{ env.NEXT_VERSION }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment