Skip to content

Commit

Permalink
ci: Split up delivery workflow into 2 jobs
Browse files Browse the repository at this point in the history
- Using jobs for controling the flow is better GitHub Actions practice than constant if checks.
- Make the names of the jobs and steps more clear.
  • Loading branch information
itislu committed Jul 29, 2024
1 parent 308bc00 commit 1a282fb
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions .github/workflows/delivery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,83 @@ on:
- 'v*'

jobs:
update_evaluation_branch:
check_tag_version:
name: Check Tag Version
runs-on: ubuntu-latest
env:
PROCEED:
MAIN_TAG:

outputs:
main_tag: ${{ steps.check_new_version.outputs.main_tag }}
is_new_version: ${{ steps.check_new_version.outputs.is_new_version }}
steps:
- name: Checkout code
- name: Checkout tag
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Lea Yeh"
- name: Check tag version
- name: Check if new version
id: check_new_version
run: |
main_tag=$(git tag --sort=-creatordate --merged origin/main 2>/dev/null | head -n 1) || true
eval_tag=$(git tag --sort=-creatordate --no-merged origin/main 2>/dev/null | head -n 1) || true
echo "MAIN_TAG: $main_tag"
echo "EVAL_TAG: $eval_tag"
echo MAIN_TAG=$main_tag >> "$GITHUB_ENV"
echo "main_tag=$main_tag" >> $GITHUB_OUTPUT
if [[ "$main_tag" > "$eval_tag" ]]; then
echo "PROCEED=true" >> "$GITHUB_ENV"
echo "is_new_version=true" >> $GITHUB_OUTPUT
else
echo "PROCEED=false" >> "$GITHUB_ENV"
echo "is_new_version=false" >> $GITHUB_OUTPUT
fi
update_evaluation_branch:
name: Update Evaluation Branch
needs: check_tag_version
if: needs.check_tag_version.outputs.is_new_version == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout tag
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Lea Yeh"
- name: Save .github directory
if: env.PROCEED == 'true'
run: |
cp -rf .github ~/.github
- name: Setup evaluation branch
if: env.PROCEED == 'true'
run: |
git checkout -b evaluation origin/evaluation || git checkout -b evaluation
git merge origin/main || (git checkout --theirs . && git add -A)
- name: Restore .github directory
if: env.PROCEED == 'true'
run: |
rm -rf .github
mv ~/.github .github
- name: Partial cleanup of forbidden files
if: env.PROCEED == 'true'
uses: ./.github/actions/cleanup_partial

- name: Commit partial cleanup to evaluation branch
if: env.PROCEED == 'true'
run: |
git add -A
git commit -m "[GH-BOT] Remove forbidden files and empty folders"
- name: 📏 Check norminette
if: env.PROCEED == 'true'
uses: ./.github/actions/norminette

- name: Full cleanup of forbidden files
if: env.PROCEED == 'true'
uses: ./.github/actions/cleanup_full

- name: Amend full cleanup to evaluation branch
if: env.PROCEED == 'true'
run: |
git add -A
git commit --amend --no-edit
- name: 🏷️ Set version tag on evaluation branch
if: env.PROCEED == 'true'
run: |
EVAL_TAG="${{ env.MAIN_TAG }}-eval"
EVAL_TAG="${{ needs.check_tag_version.outputs.main_tag }}-eval"
git tag "$EVAL_TAG"
git push origin evaluation "$EVAL_TAG"
git push origin evaluation "$EVAL_TAG"

0 comments on commit 1a282fb

Please sign in to comment.