diff --git a/.github/actions/get-image-tag/action.yml b/.github/actions/get-image-tag/action.yml new file mode 100644 index 000000000..87bdba19e --- /dev/null +++ b/.github/actions/get-image-tag/action.yml @@ -0,0 +1,38 @@ +name: "#️⃣ Get image tag (action)" + +description: This action gets the image tag from the commit ref or input (if provided) + +outputs: + tag: + description: The image tag + value: ${{ steps.get_tag.outputs.tag }} + +runs: + using: "composite" + steps: + - name: "#️⃣ Get image tag (step)" + id: get_tag + shell: bash + run: | + if [[ "${{ github.ref_type }}" == "tag" ]]; then + if [[ "${{ github.ref_name }}" == infra-*-* ]]; then + env=$(echo ${{ github.ref_name }} | cut -d- -f2) + sha=$(echo ${{ github.sha }} | head -c7) + ts=$(date +%s) + tag=${env}-${sha}-${ts} + elif [[ "${{ github.ref_name }}" == v.docker.* ]]; then + version="${GITHUB_REF_NAME#v.docker.}" + tag="v${version}" + elif [[ "${{ github.ref_name }}" == build-* ]]; then + tag="${GITHUB_REF_NAME#build-}" + else + echo "Invalid tag: ${{ github.ref_name }}" + exit 1 + fi + elif [[ "${{ github.ref_name }}" == "main" ]]; then + tag="main" + else + echo "Invalid reference: ${{ github.ref }}" + exit 1 + fi + echo "tag=${tag}" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index cd0bc3f4c..c95d683f1 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -9,7 +9,7 @@ jobs: env: PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING: 1 outputs: - version: ${{ steps.get_version.outputs.version }} + version: ${{ steps.get_tag.outputs.tag }} short_sha: ${{ steps.get_commit.outputs.sha_short }} steps: - name: Setup Depot CLI @@ -20,45 +20,27 @@ jobs: with: submodules: recursive - - name: 🆚 Get the version - id: get_version - run: | - IMAGE_TAG="${GITHUB_REF#refs/tags/}" - if [[ $GITHUB_REF == refs/tags/* ]]; then - if [[ $IMAGE_TAG == v.docker.* ]]; then - ORIGINAL_VERSION="${IMAGE_TAG#v.docker.}" - IMAGE_TAG="v${ORIGINAL_VERSION}" - elif [[ $IMAGE_TAG == build-* ]]; then - IMAGE_TAG="${IMAGE_TAG#build-}" - fi - echo "IMAGE_TAG=${IMAGE_TAG}" - elif [[ $GITHUB_REF == refs/heads/main ]]; then - # Handle main branch specifically - IMAGE_TAG="main" - echo "IMAGE_TAG=${IMAGE_TAG}" - else - echo "Invalid reference: ${GITHUB_REF}" - exit 1 - fi - echo "::set-output name=version::${IMAGE_TAG}" + - name: "#️⃣ Get the image tag" + id: get_tag + uses: ./.github/actions/get-image-tag - name: 🔢 Get the commit hash id: get_commit run: | - echo ::set-output name=sha_short::$(echo ${{ github.sha }} | cut -c1-7) + echo "sha_short=$(echo ${{ github.sha }} | cut -c1-7)" >> "$GITHUB_OUTPUT" - name: 📛 Set the tags id: set_tags run: | ref_without_tag=ghcr.io/triggerdotdev/trigger.dev - image_tags=$ref_without_tag:${{ steps.get_version.outputs.version }} + image_tags=$ref_without_tag:${{ steps.get_tag.outputs.tag }} # if it's a versioned tag, also tag it as v3 if [[ "${{ github.ref_name }}" == v.docker.* ]]; then image_tags=$image_tags,$ref_without_tag:v3 fi - - echo "IMAGE_TAGS=${image_tags}" >> "$GITHUB_OUTPUT" + + echo "image_tags=${image_tags}" >> "$GITHUB_OUTPUT" - name: 🐙 Login to GitHub Container Registry uses: docker/login-action@v3 @@ -72,5 +54,5 @@ jobs: with: file: ./docker/Dockerfile platforms: linux/amd64,linux/arm64 - tags: ${{ steps.set_tags.outputs.IMAGE_TAGS }} + tags: ${{ steps.set_tags.outputs.image_tags }} push: true diff --git a/.github/workflows/publish-infra.yml b/.github/workflows/publish-infra.yml index ca9dd885d..c9d3e7775 100644 --- a/.github/workflows/publish-infra.yml +++ b/.github/workflows/publish-infra.yml @@ -45,41 +45,19 @@ jobs: - name: ⬇️ Checkout git repo uses: actions/checkout@v4 - - name: Generate image reference - id: prep + - name: 📦 Get image repo + id: get_repository run: | - # set image repo if [[ "${{ matrix.package }}" == *-provider ]]; then provider_type=$(echo "${{ matrix.package }}" | cut -d- -f1) - repository=provider/${provider_type} + repo=provider/${provider_type} else - repository="${{ matrix.package }}" + repo="${{ matrix.package }}" fi - echo "REPOSITORY=${repository}" >> "$GITHUB_OUTPUT" + echo "repo=${repo}" >> "$GITHUB_OUTPUT" - # set image tag - if [[ "${{ github.ref_type }}" == "tag" ]]; then - if [[ "${{ github.ref_name }}" == infra-*-* ]]; then - env=$(echo ${{ github.ref_name }} | cut -d- -f2) - sha=$(echo ${{ github.sha }} | head -c7) - ts=$(date +%s) - image_tag=${env}-${sha}-${ts} - elif [[ "${{ github.ref_name }}" == v.docker.* ]]; then - version="${GITHUB_REF_NAME#v.docker.}" - image_tag="v${version}" - elif [[ "${{ github.ref_name }}" == build-* ]]; then - image_tag="${GITHUB_REF_NAME#build-}" - else - echo "Invalid tag: ${{ github.ref_name }}" - exit 1 - fi - elif [[ "${{ github.ref_name }}" == "main" ]]; then - image_tag="main" - else - echo "Invalid reference: ${{ github.ref }}" - exit 1 - fi - echo "IMAGE_TAG=${image_tag}" >> "$GITHUB_OUTPUT" + - id: get_tag + uses: ./.github/actions/get-image-tag - name: 🐋 Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -109,8 +87,8 @@ jobs: docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG env: REGISTRY: ghcr.io/triggerdotdev - REPOSITORY: ${{ steps.prep.outputs.REPOSITORY }} - IMAGE_TAG: ${{ steps.prep.outputs.IMAGE_TAG }} + REPOSITORY: ${{ steps.get_repository.outputs.repo }} + IMAGE_TAG: ${{ steps.get_tag.outputs.tag }} - name: 🐙 Push 'v3' tag to GitHub Container Registry if: startsWith(github.ref_name, 'v.docker.') @@ -119,4 +97,4 @@ jobs: docker push $REGISTRY/$REPOSITORY:v3 env: REGISTRY: ghcr.io/triggerdotdev - REPOSITORY: ${{ steps.prep.outputs.REPOSITORY }} + REPOSITORY: ${{ steps.get_repository.outputs.repo }}