Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BI-5142)fix: release build #183

Merged
merged 14 commits into from
Dec 19, 2023
32 changes: 9 additions & 23 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,17 @@ jobs:
strategy:
matrix:
image_name:
- "dl-control-api"
- "dl-data-api"
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/debian_docker:latest"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- "datalens-control-api"
- "datalens-data-api"
env:
cr_url: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}"
image_url_base: "${{ env.cr_url }}/${{ matrix.image_name }}"
image_url_release: "${{ env.image_url_base }}:${{ github.event.inputs.version }}"
image_url_rc: "${{ env.image_url_base }}:${{ github.event.inputs.version }}rc1"
image_url_latest: "${{ env.image_url_base }}:latest"
cr_url: "ghcr.io/${{ github.repository_owner }}"
image_url_rc: "ghcr.io/${{ github.repository_owner }}/${{ matrix.image_name }}:${{ github.event.inputs.version }}rc1"

steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.CR_TAG_BASE }}
registry: ${{ env.cr_url }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -57,15 +48,10 @@ jobs:
id: push_image
run: |
echo "Pushing release image"
docker tag ${{ env.image_url_rc }} ${{ env.image_url_release }}
docker push ${{ env.image_url_release }}

- name: Push latest tag
if: ${{ github.event.inputs.make_latest == 'true' }}
run: |
echo "Pushing latest image"
docker tag ${{ env.image_url_rc }} ${{ env.image_url_latest }}
docker push ${{ env.image_url_latest }}
docker tag "${{ env.image_url_rc }}" "${{ env.image_tag }}"
docker push "${{ env.image_tag }}"
env:
image_tag: "${{ env.cr_url }}/${{ matrix.image_name }}:${{ github.event.inputs.version }}"

release:
name: "Create release"
Expand Down
93 changes: 56 additions & 37 deletions .github/workflows/release_prerelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,95 @@ on:
default: false

jobs:
get_version:
name: "Get version"
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
id: checkout
if: ${{ github.event.inputs.version == '' }}
uses: actions/checkout@v2
with:
ref: "${{ github.event.inputs.branch }}"
fetch-depth: 0

- name: Get version
id: get_version
run: |
version=${{ github.event.inputs.version }}
if [[ -z "${version}" ]]; then
latest_tag=$(git describe --tags --abbrev=0)
latest_version="${latest_tag%rc*}"
echo "Latest version is ${latest_version}"
version=$(.github/.scripts/shift_version.sh ${latest_version} ${{ github.event.inputs.version_shift }})
fi

echo "version=${version}" >> $GITHUB_OUTPUT

build_images:
name: "Build images"
needs: [get_version]
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
image_name:
- "dl-control-api"
- "dl-data-api"
include:
- image_name: "datalens-control-api"
bake_target: "dl_control_api"
- image_name: "datalens-data-api"
bake_target: "dl_data_api"
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/debian_docker:latest"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
cr_url: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}"
image_url_base: "${{ env.cr_url }}/${{ matrix.image_name }}"
image_url_rc: "${{ env.image_url_base }}:${{ github.event.inputs.version }}rc1"
image_url_release: "${{ env.image_url_base }}:${{ github.event.inputs.version }}"
version: "${{ needs.get_version.outputs.version }}"
cr_url: "ghcr.io/${{ github.repository_owner }}"

steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.CR_TAG_BASE }}
registry: ${{ env.cr_url }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
id: checkout
uses: actions/checkout@v2
with:
ref: "${{ env.branch }}"
ref: "${{ github.event.inputs.branch }}"
fetch-depth: 0

- name: Build image
working-directory: docker_build
run: |
image_name="${{ matrix.image_name }}"
bake_target="${image_name/-/_}" # replace - with _
bake_target=${{ matrix.bake_target }}

./run-project-bake "${bake_target}" \
--push \
--set "${bake_target}.tags=${{ env.image_url_rc }}"
${{ github.event.inputs.with_release == 'true' && '--set "${bake_target}.tags=${{ env.image_url_release }}"' || '' }}
env:
image_url_rc: "${{ env.cr_url }}/${{ matrix.image_name }}:${{ env.version }}rc1"
image_url_release: "${{ env.cr_url }}/${{ matrix.image_name }}:${{ env.version }}"

release:
name: "Create prerelease"
needs: [build_images]
needs: [build_images, get_version]
runs-on: ubuntu-latest
permissions:
contents: write
env:
version: "${{ needs.get_version.outputs.version }}"
release_branch: "release/${{ needs.get_version.outputs.version }}"
steps:
- name: Checkout code
id: checkout
Expand All @@ -86,51 +121,35 @@ jobs:
ref: "${{ github.event.inputs.branch }}"
fetch-depth: 0

- name: Get version
id: get_version
working-directory: .github/.scripts
run: |
version=${{ github.event.inputs.version }}
if [[ -z "${version}" ]]; then
latest_tag=$(git describe --tags --abbrev=0)
latest_version="${latest_tag%rc*}"
echo "Latest version is ${latest_version}"
version=$(./shift_version.sh ${latest_version} ${{ github.event.inputs.version_shift }})
fi
release_branch="release/${version}"
tag_name="${version}rc1"

echo "version=${version}" >> $GITHUB_OUTPUT
echo "release_branch=${release_branch}" >> $GITHUB_OUTPUT
echo "tag_name=${tag_name}" >> $GITHUB_OUTPUT

- name: Create and push release branch
id: create_branch
if: ${{ github.event.inputs.branch != steps.get_version.outputs.release_branch }}
if: ${{ github.event.inputs.branch != env.release_branch }}
run: |
git branch ${{ steps.get_version.outputs.release_branch }}
git push origin ${{ steps.get_version.outputs.release_branch }}
git branch ${{ env.release_branch }}
git push origin ${{ env.release_branch }}

- name: Create prerelease
id: create_prerelease
run: |
gh release create \
--repo ${{ github.repository_owner }}/${{ github.event.repository.name }} \
${{ steps.get_version.outputs.tag_name }} \
--target ${{ steps.get_version.outputs.release_branch }} \
${{ env.release_tag }} \
--target ${{ env.release_branch }} \
--prerelease \
--generate-notes
env:
GH_TOKEN: ${{ github.token }}
release_tag: "${{ env.version }}rc1"

- name: Create release
id: create_release
if: ${{ github.event.inputs.with_release == 'true' }}
run: |
gh release create \
--repo ${{ github.repository_owner }}/${{ github.event.repository.name }} \
${{ steps.get_version.outputs.version }} \
--target ${{ steps.get_version.outputs.release_branch }} \
${{ env.release_tag }} \
--target ${{ env.release_branch }} \
--generate-notes
env:
GH_TOKEN: ${{ github.token }}
release_tag: "${{ env.version }}"
Loading