Merge pull request #1 from Yatharth0045/test-branch #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: First Workflow | |
on: | |
push: | |
# branches-ignore: | |
# - feature/* | |
# - feature/** | |
branches: | |
- main | |
- '!feature/*' | |
pull_request: | |
# activity types | |
types: | |
- review_requested | |
- ready_for_review | |
# filters | |
paths-ignore: | |
- README.md | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Select Environment' | |
required: true | |
type: choice | |
options: | |
- dev | |
- staging | |
- prod | |
env: | |
TOOL: docker | |
CONTAINER_REGISTRY: docker.io | |
jobs: | |
first_job: | |
if: github.ref != 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Welcome message | |
run: echo 'My First Github Actions Job' | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository }} | |
- name: Read Readme | |
run: cat README.md | |
- name: List Files | |
run: ls | |
- name: Print envs | |
run: printenv | |
- name: Perform multiple actions | |
run: | | |
echo 'Running multiple commands' | |
ls -a | |
- name: Installing cowsay | |
run: sudo apt install cowsay -y | |
- name: Execute cowsay | |
run: | | |
cowsay -f dragon "Hello Yatharth!!" >> drag.txt | |
cat drag.txt | |
- name: Execute shell script | |
run: | | |
chmod +x cowsay-script.sh | |
./cowsay-script.sh | |
- name: Upload files | |
uses: actions/upload-artifact@v4.4.3 | |
with: | |
name: dragon | |
path: drag.txt | |
second_job: | |
runs-on: ubuntu-latest | |
needs: | |
- first_job | |
steps: | |
- name: Welcome message | |
run: echo 'My Second Github Actions Job' | |
- name: Download a Build Artifact | |
uses: actions/download-artifact@v4.1.8 | |
with: | |
name: dragon | |
- name: Check cowsay | |
run: | | |
ls -la | |
cat drag.txt | |
docker_job: | |
if: github.ref != 'refs/heads/main' | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_REPOSITORY_NAME: yatharth0045 | |
IMAGE_NAME: cowsay | |
IMAGE_VERSION: latest | |
steps: | |
- name: Check docker | |
env: | |
DOCKER_TASK: version | |
run: ${{ env.TOOL }} --$DOCKER_TASK | |
- name: Check containers | |
run: ${{ env.TOOL }} ps | |
- name: Clone repo | |
uses: actions/checkout@v4 | |
- name: Build Docker | |
env: | |
DOCKER_TASK: build | |
run: ${{ env.TOOL }} build -t ${{ env.CONTAINER_REGISTRY }}/${{ env.DOCKER_REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_VERSION }} . | |
- name: Login Docker | |
run: ${{ env.TOOL }} login --username=${{ vars.DOCKER_USERNAME }} --password=${{ secrets.DOCKER_PASSWORD }} | |
- name: Get Docker Secrets | |
run: cat /home/runner/.docker/config.json | |
- name: Docker Publish | |
env: | |
DOCKER_TASK: push | |
run: ${{ env.TOOL }} push ${{ env.CONTAINER_REGISTRY }}/${{ env.DOCKER_REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_VERSION }} | |
dynamic_env_job: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setting up ENV | |
env: | |
ENVIRONMENT: ${{ inputs.environment }} | |
run: | | |
if [ ${{ env.ENVIRONMENT }} == "dev" ]; then | |
AWS_ACCOUNT_ID='0123' | |
elif [ ${{ env.ENVIRONMENT }} == "staging" ]; then | |
AWS_ACCOUNT_ID='0246' | |
elif [ ${{ env.ENVIRONMENT }} == "prod" ]; then | |
AWS_ACCOUNT_ID='1234' | |
fi | |
echo "AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID" >> $GITHUB_ENV | |
echo "Running Terraform apply for env: ${{env.ENVIRONMENT}} with account id: $AWS_ACCOUNT_ID" | |
- name: Dump Env | |
env: | |
ENV_CONFIG: ${{ toJson(env) }} | |
run: | | |
echo "$ENV_CONFIG" | |
echo "==========" | |
echo "Running Terraform apply for env: ${{ inputs.environment }} with account id: $AWS_ACCOUNT_ID" | |
echo "Running Terraform apply for env: ${{ inputs.environment }} with account id: ${{ env.AWS_ACCOUNT_ID }}" | |
echo "Running Terraform apply for env: ${{ inputs.environment }} with account id: $AWS_ACCOUNT_ID:Completed" | |
echo "==========" |