Compare commits

...

11 Commits

Author SHA1 Message Date
Sebastian Weigand 2cd830db7c
Merge aabe83c06d into 93e87954aa 2024-11-15 04:59:28 +01:00
🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) 93e87954aa
Merge pull request #301 from br3ndonland/ghcr-sha 2024-11-15 04:22:10 +01:00
Brendon Smith f81cd95ad9
Tag Docker images with Git SHA
PR https://github.com/pypa/gh-action-pypi-publish/pull/230 updated the
action to pull Docker images from GHCR instead of building Docker images
each time the workflow runs. As part of this PR, a new GitHub Actions
workflow was added that builds Docker images and pushes them to GitHub
Container Registry (GHCR).

Actions can be referenced in various ways. The Docker build workflow
covers most of the action references, but does not push Docker images
tagged with the Git commit ID (Git SHA).

This commit will add Docker tags for referencing the action with a Git
SHA. GitHub Actions only supports references by the full 40 character
SHA. If users try to reference the action by a short SHA like `1234567`,
they will get an error like, "Unable to resolve action
`pypa/gh-action-pypi-publish@1234567`, the provided ref `1234567` is the
shortened version of a commit SHA, which is not supported. Please use
the full commit SHA `1234567890123456789012345678901234567890` instead."

https://github.com/pypa/gh-action-pypi-publish/pull/230
https://github.com/pypa/gh-action-pypi-publish/issues/290
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-pre-written-building-blocks-in-your-workflow#using-shas
2024-11-11 18:58:36 -05:00
s-weigand aabe83c06d Added sha of original commit to tag commit message 2020-11-09 17:36:18 +01:00
s-weigand bf26813dfe Improved tag message 2020-11-06 15:58:16 +01:00
s-weigand 1ef704e0ad Split up git user setup, tag creation and tag pushing in separate tasks
See https://github.com/pypa/gh-action-pypi-publish/pull/45#discussion_r517258942
2020-11-06 15:48:44 +01:00
Sebastian Weigand 5fbbe92f7f
Make Tag pushing atomic
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
2020-11-06 15:39:23 +01:00
Sebastian Weigand 54e3ca66c3 Unnest outpust creation
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
2020-11-06 15:37:11 +01:00
s-weigand 5baaafca44 Applied requested changes 2020-11-04 00:51:15 +01:00
s-weigand b78d2e95c3 Use 'shell : python' instead of script 2020-11-04 00:50:55 +01:00
s-weigand e34653ec97 Add major-minor-release workflow 2020-11-03 16:55:19 +01:00
2 changed files with 66 additions and 0 deletions

View File

@ -32,15 +32,18 @@ jobs:
IMAGE="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG}" IMAGE="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG}"
IMAGE_MAJOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR}" IMAGE_MAJOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR}"
IMAGE_MAJOR_MINOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR_MINOR}" IMAGE_MAJOR_MINOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR_MINOR}"
IMAGE_SHA="ghcr.io/$GITHUB_REPOSITORY:${GITHUB_SHA}"
echo "IMAGE=$IMAGE" >>"$GITHUB_ENV" echo "IMAGE=$IMAGE" >>"$GITHUB_ENV"
echo "IMAGE_MAJOR=$IMAGE_MAJOR" >>"$GITHUB_ENV" echo "IMAGE_MAJOR=$IMAGE_MAJOR" >>"$GITHUB_ENV"
echo "IMAGE_MAJOR_MINOR=$IMAGE_MAJOR_MINOR" >>"$GITHUB_ENV" echo "IMAGE_MAJOR_MINOR=$IMAGE_MAJOR_MINOR" >>"$GITHUB_ENV"
echo "IMAGE_SHA=$IMAGE_SHA" >>"$GITHUB_ENV"
docker build . \ docker build . \
--build-arg BUILDKIT_INLINE_CACHE=1 \ --build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $IMAGE \ --cache-from $IMAGE \
--tag $IMAGE --tag $IMAGE
docker tag $IMAGE $IMAGE_MAJOR docker tag $IMAGE $IMAGE_MAJOR
docker tag $IMAGE $IMAGE_MAJOR_MINOR docker tag $IMAGE $IMAGE_MAJOR_MINOR
docker tag $IMAGE $IMAGE_SHA
env: env:
DOCKER_TAG: ${{ inputs.tag || github.ref_name }} DOCKER_TAG: ${{ inputs.tag || github.ref_name }}
- name: Log in to GHCR - name: Log in to GHCR
@ -52,3 +55,4 @@ jobs:
docker push $IMAGE docker push $IMAGE
docker push $IMAGE_MAJOR docker push $IMAGE_MAJOR
docker push $IMAGE_MAJOR_MINOR docker push $IMAGE_MAJOR_MINOR
docker push $IMAGE_SHA

View File

@ -0,0 +1,62 @@
name: "Publish Major-Minor-Tags"
on:
push:
tags:
- "v*"
jobs:
push-tags:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install packaging
run: python -m pip install -U packaging --user
- name: Get versions
id: get_versions
shell: python
run: |
from packaging.version import parse
tag_ref = "${{ github.ref }}"
tag_name = tag_ref.split("/")[-1]
version = parse(tag_name)
print(f"tag_name: {tag_name}")
print(f"version: {version}")
if version.is_prerelease:
print("No tags created (dev or pre version)!")
exit(0)
print("Creating new major and minor tags!")
print(f"::set-output name=original_tag_name::{tag_name}")
print(f"::set-output name=major_version::v{version.major}")
print(f"::set-output name=minor_version::v{version.major}.{version.minor}")
- name: Setup git user as [bot]
run: |
git config user.email 'github-actions[bot]@users.noreply.github.com'
git config user.name 'github-actions[bot]'
- name: Create major + minor tags
if: steps.get_versions.outputs.original_tag_name != ''
env:
original_tag_name: ${{ steps.get_versions.outputs.original_tag_name }}
major_version: ${{ steps.get_versions.outputs.major_version }}
minor_version: ${{ steps.get_versions.outputs.minor_version }}
run: |
git tag --annotate '${{ env.major_version }}' \
--message='Major version tag of: ${{ env.original_tag_name }}' \
--message="Original tag SHA1: $(git rev-parse ${{ env.original_tag_name }})"
git tag --annotate '${{ env.minor_version }}' \
--message='Minor version tag of: ${{ env.original_tag_name }}' \
--message="Original tag SHA1: $(git rev-parse ${{ env.original_tag_name }})"
- name: Push major + minor tags
if: steps.get_versions.outputs.original_tag_name != ''
env:
major_version: ${{ steps.get_versions.outputs.major_version }}
minor_version: ${{ steps.get_versions.outputs.minor_version }}
run: |
git push --force --atomic origin \
'${{ env.major_version }}' \
'${{ env.minor_version }}'