Created
May 25, 2023 19:11
-
-
Save smoonlee/46582784faac2264a28cd7b331ec600e 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 Container (Manual Trigger) | |
on: | |
workflow_dispatch | |
jobs: | |
get_package_version: | |
name: Get Package Version | |
runs-on: ubuntu-latest | |
outputs: | |
current_version: ${{ steps.get_package_version.outputs.CURRENT_VERSION }} | |
updated_version: ${{ steps.get_package_version.outputs.UPDATED_VERSION }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Get Package Version | |
id: get_package_version | |
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") | |
tag_version=$(echo "$response" | jq -r '.[0].metadata.container.tags[0]') | |
# Increment the version manually | |
IFS='.' read -ra version_parts <<< "$tag_version" | |
patch=$((version_parts[2] + 1)) | |
next_version="${version_parts[0]}.${version_parts[1]}.$patch" | |
echo "::set-output name=CURRENT_VERSION::$tag_version" | |
echo "::set-output name=UPDATED_VERSION::$next_version" | |
build_docker_image: | |
name: Build Docker Image | |
needs: get_package_version | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Display Package Versions | |
run: | | |
echo "Current version: ${{ needs.get_package_version.outputs.current_version }}" | |
echo "Next Release : ${{ needs.get_package_version.outputs.updated_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: ${{ needs.get_package_version.outputs.updated_version }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment