-
Notifications
You must be signed in to change notification settings - Fork 2
90 lines (75 loc) · 3.37 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: Test-Workflow
# name of GitHub event that triggers workflow
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#external-events-repository_dispatch
# on: [repository_dispatch]
# it's possible to filter whole workflow using custom type sent, eg: from ValidateSet here:
# https://github.com/adamrushuk/github-actions/blob/master/TriggerCustomAction.ps1#L33
on:
repository_dispatch:
types: [test]
# enable manual workflow
# https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#manually-running-a-workflow
workflow_dispatch:
inputs:
name:
description: 'Mandatory var'
required: true
default: 'Adam'
home:
description: 'Optional var'
required: false
# global environment variables
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
env:
MY_WORKFLOW_VAR: work
# TODO Currently Unsupported: Cannot concatenante at Workflow level
MY_CONCATENATED_WORKFLOW_VAR: "$MY_WORKFLOW_VAR-workflowvalue02"
jobs:
build:
# always pin versions
# # view installed software: https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners
runs-on: ubuntu-22.04
env:
MY_JOB_VAR: job
# TODO Currently Unsupported: Cannot concatenante at Job level
# MY_WORK_JOB_VAR: "${{ env.MY_WORKFLOW_VAR }}-test"
steps:
# Checkout
- uses: actions/checkout@v4
# Show event info
- name: Show triggered event data
run: pwsh -command "./scripts/Get-EventData.ps1"
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
# WORKAROUND Env var concatenation
# https://github.community/t5/GitHub-Actions/How-can-we-concatenate-multiple-env-vars-at-workflow-and-job/td-p/48489
- name: BASH - Concatenate env vars (Workaround)
run: |
echo "MY_CONCATENATED_BASH_VAR=${{ env.MY_WORKFLOW_VAR }}-${{ env.MY_JOB_VAR }}-bash-stepvalue01" >> $GITHUB_ENV
- name: PWSH - Concatenate env vars (Workaround)
# override the default bash shell, as running on ubuntu
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell
shell: pwsh
# pwsh requires double quotes when setting env vars
run: |
echo "MY_CONCATENATED_PWSH_VAR=${{ env.MY_WORKFLOW_VAR }}-${{ env.MY_JOB_VAR }}-pwsh-stepvalue01" | Out-File -Append -Encoding utf8 -FilePath "$env:GITHUB_ENV"
- name: Output event data
shell: pwsh
env:
MY_STEP_VAR: step
run: |
# Env var concatenation
Write-Output "MY_WORKFLOW_VAR is: [$env:MY_WORKFLOW_VAR]"
Write-Output "MY_JOB_VAR is: [$env:MY_JOB_VAR]"
Write-Output "MY_STEP_VAR is: [$env:MY_STEP_VAR]"
Write-Output "MY_CONCATENATED_WORKFLOW_VAR is: [$env:MY_CONCATENATED_WORKFLOW_VAR]"
Write-Output "MY_CONCATENATED_BASH_VAR is: [$env:MY_CONCATENATED_BASH_VAR]"
Write-Output "MY_CONCATENATED_PWSH_VAR is: [$env:MY_CONCATENATED_PWSH_VAR]"
Write-Output "SLACK_JSON is: [$env:SLACK_JSON]"
# Notify
- name: Notify slack
env:
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
run: ./scripts/send_slack_message.sh "[devops-lab] Test notification"