Skip to content

Update 00-firstworkflow.yaml #20

Update 00-firstworkflow.yaml

Update 00-firstworkflow.yaml #20

name: 00-first workflow
on:
push:
pull_request:
branches:
- main
workflow_dispatch:
inputs:
branch:
description: 'Branch to test'
type: string
default: 'dev'
input1:
description: 'Input 1'
type: string
default: 'efg'
input2:
description: 'Input 2'
type: number
default: 123
jobs:
echo-hello:
runs-on: ubuntu-latest
env:
ENV_VAR1: 1234
ENV_VAR2: "abcd"
ENV_VAR3: ${{ github.event.inputs.input1 }}
ENV_VAR4: ${{ github.event.inputs.input2 }}
steps:
- name: Trigger
run: echo "Triggered by ${{ github.event_name }} event"
- name: Check Branch Input
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
if [ -z "${{ github.event.inputs.branch }}" ]; then
echo "Branch input is required for manual trigger."
exit 1
else
BRANCH_NAME="${{ github.event.inputs.branch }}"
fi
else
# Extract branch name from github.ref
BRANCH_NAME="${{ github.ref }}"
BRANCH_NAME="${BRANCH_NAME##*/}" # This removes everything before the last '/'
fi
echo "Checkout branch $BRANCH_NAME"
- name: Verify directory1
run: |
echo "Repo root directory: $GITHUB_WORKSPACE"
echo "Current directory: $PWD"
echo "Cloned to: $(pwd)"
ls -la /home/runner/work/${{ github.event.repository.name }}
ls -la $GITHUB_WORKSPACE
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branch || github.ref }}
- name: Verify directory2
run: |
echo "Repo root directory: $GITHUB_WORKSPACE"
echo "Current directory: $PWD"
echo "Cloned to: $(pwd)"
echo "ls -la /home/runner/work/${{ github.event.repository.name }}:"
ls -la /home/runner/work/${{ github.event.repository.name }}
echo "ls -la $GITHUB_WORKSPACE"
ls -la $GITHUB_WORKSPACE
- name: Move to custom workspace
run: |
mv "$GITHUB_WORKSPACE"/* "$(dirname "$GITHUB_WORKSPACE")"
#rm -rf "$GITHUB_WORKSPACE" # Delete the empty folder
cd ..
- name: Verify directory3
run: |
echo "Current directory: $PWD"
echo "Cloned to: $(pwd)"
echo "ls -la /home/runner/work/${{ github.event.repository.name }}:"
ls -la /home/runner/work/${{ github.event.repository.name }}
- name: Log Current Branch and Commit
run: |
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Current commit: $(git rev-parse HEAD)"
- name: Export ENV variable
run: |
echo "e_var1: $ENV_VAR1"
echo "e_var2: $ENV_VAR2"
echo "e_var3: $ENV_VAR3"
echo "e_var4: $ENV_VAR4"
var1="${{ env.ENV_VAR1 }}"
var2="${{ env.ENV_VAR2 }}"
var3=$ENV_VAR1
echo "var1: $var1"
echo "var2: $var2"
echo "var3: $var3"