diff --git a/.github/workflows/versioning.yaml b/.github/workflows/versioning.yaml new file mode 100644 index 000000000..56b867fb2 --- /dev/null +++ b/.github/workflows/versioning.yaml @@ -0,0 +1,57 @@ +name: Versioning +on: + push: + # Will not trigger on a release candidate + tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] + +jobs: + versioning: + name: versioning + runs-on: ubuntu-latest + steps: + # Clone the pushed tag + - name: Clone tag + uses: actions/checkout@v4 + + # Check logs with main to prevent issues when pushing + - name: Ensure tag is current with main + run: | + git fetch origin + if [[ -n $(git log HEAD..origin/main --oneline) ]]; then + echo "❌ Your tag is missing commits from origin/main." + echo -e "\u2014 Pull from main before pushing tag." + exit 1 + else + echo "✅ Your tag has all commits from origin/main!" + fi + + # Get the tag for the prior version + - name: Get prior version + id: get_tag + run: | + PRIOR_VERSION=$(git tag -l --sort=-v:refname | grep -E "v?[0-9]+\.[0-9]+\.[0-9]+$" | head -n 1 | sed "s/v//g" | sed "s/\./-/g") + echo "PRIOR_VERSION=$PRIOR_VERSION" >> $GITHUB_ENV + echo "Prior version tag: $PRIOR_VERSION" + + # Clone the prior tag + - name: Clone prior branch + uses: actions/checkout@v4 + with: + ref: ${{ steps.get_tag.outputs.PRIOR_VERSION }} + path: prior + fetch-depth: 0 + + # Move latest of the prior tag to corresponding version folder + - name: Move prior latest to versions + shell: bash + run: | + mkdir "content/versions/$PRIOR_VERSION" + cp -r prior/content/latest "content/versions/$PRIOR_VERSION" + rm -r prior + + # Commit everything to main + - name: Commit and replace + run: | + git add . + git commit -m "Migrated ${{ github.ref_name }} into latest" + git push origin main \ No newline at end of file