-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (75 loc) · 3 KB
/
check-version.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
name: Semaphore Check Version
run-name: Auto Version Check
on:
workflow_dispatch:
schedule:
- cron: '30 3 * * *'
jobs:
check-semui-version:
name: "Version Check Job"
runs-on: ubuntu-latest
environment: staging
env:
GIT_PUSH: "false"
PYPI_VERSION: ${{ vars.PYPI_VERSION }}
ENV_FILENAME: "variable.env"
steps:
- name: Get current date
id: date
run: echo "$(date +'%Y-%m-%d %H:%M:%S')"
- name: Print PyPi Version if it is set hardcoded in repo
if: env.PYPI_VERSION != ''
run: echo $PYPI_VERSION
- name: Checkout branch "master"
uses: actions/checkout@v4
with:
ref: main
- name: Extract version from Ansible Semaphore Github API response
run: |
#PAGE_SEMAPHORE_VERSION=$(curl -s https://api.github.com/repos/ansible-semaphore/semaphore/releases/latest | jq -r '.name' | sed 's/^v//')
PAGE_SEMAPHORE_VERSION=$(curl -s https://api.github.com/repositories/23267883/releases/latest | jq -r '.name' | sed 's/^v//')
echo "Extracted version: $PAGE_SEMAPHORE_VERSION"
echo "PAGE_SEMAPHORE_VERSION=$PAGE_SEMAPHORE_VERSION" >> "$GITHUB_ENV"
shell: bash
- name: Read .env file and set env variable
id: read-version
run: |
cat $ENV_FILENAME
cat $ENV_FILENAME >> "$GITHUB_ENV"
- name: Compare versions
run: |
echo "GIT_PUSH=false" >> $GITHUB_ENV
if [ "$PAGE_SEMAPHORE_VERSION" != "$SEMAPHORE_VERSION" ]; then
echo "Versions are different. Updating SEMAPHORE."
sed -i "s/^SEMAPHORE_VERSION=.*/SEMAPHORE_VERSION=$PAGE_SEMAPHORE_VERSION/g" $ENV_FILENAME
if [ -z "$PYPI_VERSION" ]; then
echo "Variable PYPI_VERSION is not hardcoded. Set value same as Ansible Semaphore Version."
sed -i "s/^PYPI_VERSION=.*/PYPI_VERSION=$SEMAPHORE_VERSION/g" $ENV_FILENAME
else
echo "Variable PYPI_VERSION is not empty. Set value from variables."
sed -i "s/^PYPI_VERSION=.*/PYPI_VERSION=$PYPI_VERSION/g" $ENV_FILENAME
fi
echo "GIT_PUSH=true" >> $GITHUB_ENV
else
echo "Versions are the same. No update needed."
exit 0
fi
echo "Final SEMAPHORE set: $PAGE_SEMAPHORE_VERSION"
shell: bash
- name: Print new .env file version
run: |
cat $ENV_FILENAME
shell: bash
- name: Commit changes
if: env.GIT_PUSH == 'true'
run: |
git config --local user.name actions-user
git config --local user.email "github@nchekwa.com"
git status
git add variable.env
git commit -am "GitHub Actions Check Version Update $(date +"%Y-%m-%d %H:%M:%S")"
git push -f origin main
outputs:
PYPI_NAME: ${{ env.PYPI_NAME }}
PYPI_VERSION: ${{ env.PYPI_VERSION }}
SEMAPHORE_VERSION: ${{ env.SEMAPHORE_VERSION }}