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

Run workflow only if label added #1860

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions .github/workflows/adapter-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check PR Labels
id: label_check
run: |
valid_label=false
# Example: Label to check for
required_label="allow-workflow"

for label in ${{ github.event.pull_request.labels.*.name }}; do
if [ "$label" == "$required_label" ]; then
valid_label=true
break
fi
done

if [ "$valid_label" == "true" ]; then
echo "::set-output name=valid::true"
else
echo "::set-output name=valid::false"
fi
- name: Install Go
uses: actions/setup-go@v3
with:
Expand Down Expand Up @@ -74,29 +93,33 @@ jobs:
gh pr checkout ${{ github.event.number }} -b pr-${{ github.event.number }}
git checkout pr-${{ github.event.number }}
git merge origin/main
if: steps.label_check.outputs.valid == 'true'
- name: Run Release Gradle build
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_version != '' && github.event.inputs.next_version != ''
run: |
cd apk-repo/adapter
./gradlew release -Prelease.useAutomaticVersion=true -Pdocker_organization=${{ secrets.DOCKER_ORGANIZATION }} -Pdocker_username=${{ secrets.DOCKER_USERNAME }} -Pdocker_password=${{ secrets.DOCKER_PASSWORD }} -Prelease.releaseVersion=${{ github.event.inputs.release_version }} -Prelease.newVersion=${{ github.event.inputs.next_version }} -PmultiArch=true
if: steps.label_check.outputs.valid == 'true'
- name: Run Gradle Build
run: |
cd apk-repo/adapter
./gradlew build
if: steps.label_check.outputs.valid == 'true'
- name: Run Gradle Build
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
run: |
cd apk-repo/adapter
./gradlew docker_push -Pdocker_organization=${{ secrets.DOCKER_ORGANIZATION }} -Pdocker_username=${{ secrets.DOCKER_USERNAME }} -Pdocker_password=${{ secrets.DOCKER_PASSWORD }} -Pimage_version=latest -PmultiArch=true
./gradlew docker_push -Pdocker_organization=${{ secrets.DOCKER_ORGANIZATION }} -Pdocker_username=${{ secrets.DOCKER_USERNAME }} -Pdocker_password=${{ secrets.DOCKER_PASSWORD }} -Pimage_version=${{ github.sha }} -PmultiArch=true

if: steps.label_check.outputs.valid == 'true'
- name: Login to azure.
if: ${{inputs.aks_deployment}}
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
if: steps.label_check.outputs.valid == 'true'
- name: Push Docker images to aks.
if: ${{inputs.aks_deployment}}
if: ${{inputs.aks_deployment}} && steps.label_check.outputs.valid == 'true'
run: |
az acr login -n ${{ secrets.AZURE_ACR_NAME }}
cd apk-repo/adapter
Expand All @@ -106,4 +129,5 @@ jobs:
with:
verbose: true # optional (default = false)
directory: apk-repo/adapter
flags: adapter
flags: adapter
if: steps.label_check.outputs.valid == 'true'