Auto Version Check #415
This file contains 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: 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 }} |