Skip to content

Commit

Permalink
better handling of version number
Browse files Browse the repository at this point in the history
  • Loading branch information
Amateur-God committed Jun 29, 2024
1 parent f55065e commit 5656896
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
slug: ${{ steps.information.outputs.slug }}
target: ${{ steps.information.outputs.target }}
version: ${{ steps.read_version.outputs.version }}
version_changed: ${{ steps.check_version.outputs.version_changed }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
Expand All @@ -64,16 +65,19 @@
run: |
VERSION=$(cat ./${{ matrix.folder }}/version.txt)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Fetch version from main branch
id: fetch_main_version
- name: Read previous version from previous_version.txt
id: read_previous_version
run: |
git fetch origin main
MAIN_VERSION=$(git show origin/main:${{ matrix.folder }}/version.txt || echo "")
echo "main_version=$MAIN_VERSION" >> $GITHUB_OUTPUT
if [ -f ./${{ matrix.folder }}/previous_version.txt ]; then
PREVIOUS_VERSION=$(cat ./${{ matrix.folder }}/previous_version.txt)
else
PREVIOUS_VERSION=""
fi
echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
- name: Check if version has changed
id: check_version
run: |
if [ "${{ steps.read_version.outputs.version }}" = "${{ steps.fetch_main_version.outputs.main_version }}" ]; then
if [ "${{ steps.read_version.outputs.version }}" = "${{ steps.read_previous_version.outputs.previous_version }}" ]; then
echo "version_changed=false" >> $GITHUB_OUTPUT
else
echo "version_changed=true" >> $GITHUB_OUTPUT
Expand All @@ -92,20 +96,21 @@
run: |
VERSION=$(cat ./${{ matrix.folder }}/version.txt)
jq --arg version "$VERSION" '.args.BUILD_VERSION = $version' ./${{ matrix.folder }}/build.json > tmp.json && mv tmp.json ./${{ matrix.folder }}/build.json
- name: Update previous_version.txt if version has changed
if: steps.check_version.outputs.version_changed == 'true'
run: |
echo "${{ steps.read_version.outputs.version }}" > ./${{ matrix.folder }}/previous_version.txt
- name: Commit and push changes
if: steps.check_version.outputs.version_changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add ./${{ matrix.folder }}/config.json ./${{ matrix.folder }}/build.json
if ! git diff-index --quiet HEAD; then
git commit -m "Update version in config.json and build.json"
git pull --rebase origin ${{ github.ref }}
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}
else
echo "No changes to commit"
fi
git add ./${{ matrix.folder }}/config.json ./${{ matrix.folder }}/build.json ./${{ matrix.folder }}/previous_version.txt
git commit -m "Update version and previous_version.txt"
git pull origin ${{ github.ref }}
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}
- name: Debug - List extracted information
run: |
echo "Architectures: ${{ steps.information.outputs.architectures }}"
Expand All @@ -115,6 +120,7 @@
echo "Slug: ${{ steps.information.outputs.slug }}"
echo "Target: ${{ steps.information.outputs.target }}"
echo "Version: ${{ steps.read_version.outputs.version }}"
echo "Previous Version: ${{ steps.read_previous_version.outputs.previous_version }}"
echo "Version changed: ${{ steps.check_version.outputs.version_changed }}"
lint-hadolint:
Expand Down Expand Up @@ -226,7 +232,7 @@
git add ./${{ matrix.folder }}/config.json ./${{ matrix.folder }}/build.json
if ! git diff-index --quiet HEAD; then
git commit -m "Prettified Code!"
git pull --rebase origin ${{ github.ref }}
git pull origin ${{ github.ref }}
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }}
else
echo "No changes to commit"
Expand Down Expand Up @@ -473,7 +479,6 @@
name: Create and Push Docker Manifest
runs-on: ubuntu-latest
needs: build_main_or_pr
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
Expand Down Expand Up @@ -516,7 +521,6 @@
name: Create and Push Docker Manifest
runs-on: ubuntu-latest
needs: build_other_branches
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
Expand Down

0 comments on commit 5656896

Please sign in to comment.