Skip to content

Commit

Permalink
CI: change init.yml to get all information
Browse files Browse the repository at this point in the history
Instead of gambling which information are available within a action when
not directly used the init.yml gets all information via inputs.
  • Loading branch information
nichtsfrei committed Mar 19, 2024
1 parent e7ee960 commit 54e646f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto_label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: nichtsfrei/actions/pr-conventional-commit-labeler@main
- uses: greenbone/actions/pr-conventional-commit-labeler@add-pr-conventional-commit-labeler
with:
configuration_toml: release_tag.toml

25 changes: 24 additions & 1 deletion .github/workflows/control.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,33 @@ jobs:
# sets the release kind when it wasn't triggered by an workflow dispatch
# this prevents us from having to pass down all labels, event_name, etc
# to init.yml
adapt_release:
runs-on: ubuntu-latest
outputs:
kind: ${{ steps.kind.outputs.kind}}
steps:
- name: "set KIND = no_release"
run: echo "KIND=no_release" >> $GITHUB_ENV
- name: "override KIND = ${{ inputs.release }}"
if: github.event_name == 'workflow_dispatch'
run: echo "KIND=${{ inputs.release }}" >> $GITHUB_ENV
- name: "override KIND = major"
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'major_release')
run: echo "KIND=major" >> $GITHUB_ENV
- name: "override KIND = minor"
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'minor_release')
run: echo "KIND=minor" >> $GITHUB_ENV
- name: "override KIND = patch"
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'patch_release')
run: echo "KIND=patch" >> $GITHUB_ENV
- id: kind
run: |
echo "kind=${{ env.KIND }}">> "$GITHUB_OUTPUT"
init:
needs: [adapt_release]
uses: ./.github/workflows/init.yaml
with:
release: ${{ inputs.release }}
release: ${{ needs.adapt_release.outputs.kind }}
unittests:
name: unit-tests
uses: ./.github/workflows/tests.yml
Expand Down
45 changes: 22 additions & 23 deletions .github/workflows/init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ on:
inputs:
release:
type: string
ref_type:
type: string
required: false
default: ${{ github.ref_type }}
ref_name:
type: string
required: false
default: ${{ github.ref_name }}
base_ref:
type: string
required: false
default: ${{ github.base_ref }}
outputs:
docker_build_is_latest:
description: "Is used to set the tags latest and stable"
Expand Down Expand Up @@ -50,20 +62,20 @@ jobs:
fetch-depth: 0
- name: "set IS_VERSION_TAG"
run: |
echo "IS_VERSION_TAG=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
echo "IS_VERSION_TAG=${{ inputs.ref_type == 'tag' && startsWith(inputs.ref_name, 'v') }}" >> $GITHUB_ENV
# set defaults
echo "IS_LATEST_TAG=false" >> $GITHUB_ENV
- name: "set IS_LATEST_TAG"
if: ( env.IS_VERSION_TAG == 'true' )
run: |
# find the latest version that is not ourself
export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort | head -n 1)
export LATEST_VERSION=$(git tag -l | grep -v '${{ inputs.ref_name }}' | sort -r --version-sort | head -n 1)
# get major minor patch versions
IFS='.' read -r latest_major latest_minor latest_patch << EOF
$LATEST_VERSION
EOF
IFS='.' read -r tag_major tag_minor tag_patch << EOF
${{ github.ref_name }}
${{ inputs.ref_name }}
EOF
# remove leading v
latest_major=$(echo $latest_major | cut -c2-)
Expand All @@ -83,29 +95,16 @@ jobs:
run: |
echo "DOCKER_TAG=$VERSION" >> $GITHUB_ENV
- name: "set KIND = no_release"
run: echo "KIND=no_release" >> $GITHUB_ENV
- name: "override KIND = ${{ inputs.release }}"
if: github.event_name == 'workflow_dispatch'
- name: "set KIND = ${{ inputs.release }}"
run: echo "KIND=${{ inputs.release }}" >> $GITHUB_ENV
- name: "override KIND = major"
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'major_release')
run: echo "KIND=major" >> $GITHUB_ENV
- name: "override KIND = minor"
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'minor_release')
run: echo "KIND=minor" >> $GITHUB_ENV
- name: "override KIND = patch"
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'patch_release')
run: echo "KIND=patch" >> $GITHUB_ENV
- name: "set RELEASE_REF = ${{ github.ref_name }}"
if: github.base_ref == ''
run: echo "RELEASE_REF=${{ github.ref_name }}" >> $GITHUB_ENV
- name: "set RELEASE_REF = ${{ github.base_ref }}"
if: github.base_ref != ''
run: echo "RELEASE_REF=${{ github.base_ref }}" >> $GITHUB_ENV
- name: "set RELEASE_REF = ${{ inputs.ref_name }}"
if: inputs.base_ref == ''
run: echo "RELEASE_REF=${{ inputs.ref_name }}" >> $GITHUB_ENV
- name: "set RELEASE_REF = ${{ inputs.base_ref }}"
if: inputs.base_ref != ''
run: echo "RELEASE_REF=${{ inputs.base_ref }}" >> $GITHUB_ENV
- name: RELEASE_REF != NULL
run: ([ -n "${{ env.RELEASE_REF }}" ])

- name: "LATEST_VERSION"
if: inputs.release != 'no_release'
run: |
Expand Down

0 comments on commit 54e646f

Please sign in to comment.