Skip to content

Commit

Permalink
MRG: Merge pull request #15 from octue/fix-branch-tag-truncation
Browse files Browse the repository at this point in the history
Fix branch tag truncation
  • Loading branch information
cortadocodes authored Jan 29, 2024
2 parents 25179fd + 2235853 commit 1d4a51c
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 275 deletions.
63 changes: 48 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,58 @@ on:
pull_request:

jobs:
test-action:
get-package-version:
if: "!contains(github.event.head_commit.message, 'skipci')"
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
outputs:
version: ${{ steps.get-package-version.outputs.version }}
version_slug: ${{ steps.get-package-version.outputs.version_slug }}
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Install poetry
uses: snok/install-poetry@v1.3.3

- name: Get package version
id: get-package-version
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
echo "version_slug=$(poetry version -s | tr . -)" >> $GITHUB_OUTPUT
docker:
runs-on: ubuntu-latest
needs: get-package-version
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5.1.0
with:
context: .
push: true
tags: octue/get-deployment-info:${{ needs.get-package-version.outputs.version }}

test-action:
runs-on: ubuntu-latest
needs: [get-package-version, docker]
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Get deployment info
id: get-deployment-info
uses: ./
Expand All @@ -29,12 +68,6 @@ jobs:
gcp_service_name: my-test-service
gcp_environment: main

- name: Get package version
id: get-package-version
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
echo "version_slug=$(poetry version -s | tr . -)" >> $GITHUB_OUTPUT
- name: Get short SHA
id: get-short-sha
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -51,25 +84,25 @@ jobs:
- name: Check `image_latest_artifact`
uses: nick-fields/assert-action@v1
with:
expected: europe-west6-docker.pkg.dev/my-test-project/my-affix/my-test-service:pull-${{ github.event.number }}-latest
expected: europe-west6-docker.pkg.dev/my-test-project/my-affix/my-test-service:refs-pull-${{ github.event.number }}-latest
actual: ${{ steps.get-deployment-info.outputs.image_latest_artifact }}

- name: Check `image_latest_tag`
uses: nick-fields/assert-action@v1
with:
expected: pull-${{ github.event.number }}-latest
expected: refs-pull-${{ github.event.number }}-latest
actual: ${{ steps.get-deployment-info.outputs.image_latest_tag }}

- name: Check `image_version_artifact`
uses: nick-fields/assert-action@v1
with:
expected: europe-west6-docker.pkg.dev/my-test-project/my-affix/my-test-service:pull-${{ github.event.number }}
expected: europe-west6-docker.pkg.dev/my-test-project/my-affix/my-test-service:refs-pull-${{ github.event.number }}
actual: ${{ steps.get-deployment-info.outputs.image_version_artifact }}

- name: Check `image_version_tag`
uses: nick-fields/assert-action@v1
with:
expected: pull-${{ github.event.number }}
expected: refs-pull-${{ github.event.number }}
actual: ${{ steps.get-deployment-info.outputs.image_version_tag }}

- name: Check `short_sha`
Expand All @@ -81,23 +114,23 @@ jobs:
- name: Check `version`
uses: nick-fields/assert-action@v1
with:
expected: ${{ steps.get-package-version.outputs.version }}
expected: ${{ needs.get-package-version.outputs.version }}
actual: ${{ steps.get-deployment-info.outputs.version }}

- name: Check `version_slug`
uses: nick-fields/assert-action@v1
with:
expected: ${{ steps.get-package-version.outputs.version_slug }}
expected: ${{ needs.get-package-version.outputs.version_slug }}
actual: ${{ steps.get-deployment-info.outputs.version_slug }}

- name: Check `revision_tag`
uses: nick-fields/assert-action@v1
with:
expected: pull-${{ github.event.number }}
expected: refs-pull-${{ github.event.number }}
actual: ${{ steps.get-deployment-info.outputs.revision_tag }}

- name: Check `revision_tag_slug`
uses: nick-fields/assert-action@v1
with:
expected: pull-${{ github.event.number }}
expected: refs-pull-${{ github.event.number }}
actual: ${{ steps.get-deployment-info.outputs.revision_tag_slug }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.10.7-slim

RUN apt-get update -y && apt-get install -y --fix-missing curl git && rm -rf /var/lib/apt/lists/*

RUN pip3 install git+https://github.com/octue/get-deployment-info@0.2.2
RUN pip3 install git+https://github.com/octue/get-deployment-info@0.2.3

COPY get_deployment_info/entrypoint.sh /entrypoint.sh

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ steps:

- name: Get deployment info
id: get-deployment-info
uses: octue/get-deployment-info@0.2.2
uses: octue/get-deployment-info@0.2.3
with:
gcp_project_name: test-project
gcp_project_number: 1234
Expand Down Expand Up @@ -77,6 +77,6 @@ Some of the outputs' values depend on whether the action is run on the `main` br
The truncated branch name (first 12 characters) is used to ensure service names are short enough to be accepted by e.g.
Cloud Run without having to restrict the length of branch names.

- `revision_tag` is `pull-<truncated branch_tag_kebab>`
- `image_version_tag` is `pull-<truncated branch_tag_kebab>`
- `image_latest_tag` is `pull-<truncated branch_tag_kebab>-latest`
- `revision_tag` is `<truncated branch_tag_kebab>`
- `image_version_tag` is `<truncated branch_tag_kebab>`
- `image_latest_tag` is `<truncated branch_tag_kebab>-latest`
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ outputs:

runs:
using: "docker"
image: "docker://octue/get-deployment-info:0.2.2"
image: "docker://octue/get-deployment-info:0.2.3"
args:
- ${{ inputs.gcp_project_name }}
- ${{ inputs.gcp_project_number }}
Expand Down
2 changes: 1 addition & 1 deletion get_deployment_info/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if [ "$BRANCH_TAG_KEBAB" = "main" ]; then
IMAGE_VERSION_TAG="$BRANCH_TAG_KEBAB-$REVISION_TAG"
IMAGE_LATEST_TAG="$BRANCH_TAG_KEBAB-latest"
else
REVISION_TAG=pull-"${BRANCH_TAG_KEBAB:0:12}"
REVISION_TAG=$(expr substr "$BRANCH_TAG_KEBAB" 1 12)
IMAGE_VERSION_TAG="$REVISION_TAG"
IMAGE_LATEST_TAG="$REVISION_TAG-latest"
fi
Expand Down
Loading

0 comments on commit 1d4a51c

Please sign in to comment.