From a6a715c44221f0fdfd486370cfe4c8f0a155ecad Mon Sep 17 00:00:00 2001 From: 42CrMo4 <44754810+42CrMo4@users.noreply.github.com> Date: Sun, 7 Jul 2024 00:30:08 +0200 Subject: [PATCH] Update release.yml --- .github/workflows/release.yml | 260 +++++++++++++++++++++++++++++++++- 1 file changed, 254 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee6af73..2e5ee03 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,10 +12,258 @@ on: - 'v[0-9]+.[0-9]+' - 'v[0-9]+.[0-9]+-rc[0-9]+' -# ToDo: -# - if any version number is over 9 then no release is in github only the tag. - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - call-workflow-passing-data: - uses: 42CrMo4/KiCad_Workflows/.github/workflows/release.yml@ki8Diff \ No newline at end of file + determine-release-type: + runs-on: ubuntu-latest + outputs: + release-type: ${{ steps.check-tag.outputs.release-type }} + steps: + - name: Check tag + id: check-tag + run: | + if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+$ ]]; then + echo "release-type=release" >> $GITHUB_OUTPUT + elif [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then + echo "release-type=rc" >> $GITHUB_OUTPUT + else + echo "Invalid tag format" + exit 1 + fi + + ERC: + runs-on: ubuntu-latest + container: ghcr.io/inti-cmnb/kicad8_auto:1.7.0 + steps: + - uses: actions/checkout@v4 + - name: Run ERC + run: | + [ -f *.kicad_sch ] && kiplot -d Fabrication_temp -s update_xml,run_drc -i + + DRC: + runs-on: ubuntu-latest + container: ghcr.io/inti-cmnb/kicad8_auto:1.7.0 + needs: ERC + steps: + - uses: actions/checkout@v4 + - name: Run DRC + run: | + [ -f *.kicad_pcb ] && kiplot -d Fabrication_temp -s update_xml,run_erc -i + + Fabrication: + name: Fabrication files + runs-on: ubuntu-latest + permissions: + contents: write + needs: [DRC, determine-release-type] + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: '0' + + - name: List tags and set environment variables + run: | + # Fetch all tags and prune deleted references + # git fetch --prune --unshallow + + # Sort tags, placing non-pre-release tags last + sorted_tags=$(git tag | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//') + + # Get the most recent tag + last_tag=$(echo "$sorted_tags" | tail -n 1) + + # Initialize arrays for pre-release and regular release tags + pre_release_tags=() + release_tags=() + + # Categorize tags into pre-release and regular release + for tag in $(git tag); do + if [[ $tag =~ rc ]]; then + pre_release_tags+=("$tag") + else + release_tags+=("$tag") + fi + done + + # Get the last pre-release and regular release tags + pre_release_last_tag=${pre_release_tags[-1]} + non_pre_release_last_tag=${release_tags[-1]} + + # Get the second to last pre-release and regular release tags + pre_release_second_to_last_tag=${pre_release_tags[-2]} + non_pre_release_second_to_last_tag=${release_tags[-2]} + + # Set environment variables + echo "LAST_TAG=$last_tag" >> $GITHUB_ENV + echo "PRE_RELEASE_LAST_TAG=$pre_release_last_tag" >> $GITHUB_ENV + echo "last_tag=$non_pre_release_last_tag" >> $GITHUB_ENV + echo "PRE_RELEASE_SECOND_TO_LAST_TAG=$pre_release_second_to_last_tag" >> $GITHUB_ENV + echo "NON_PRE_RELEASE_SECOND_TO_LAST_TAG=$non_pre_release_second_to_last_tag" >> $GITHUB_ENV + + # Check if the latest tag is a non-rc tag and find corresponding rc tag + if [[ ! $last_tag =~ rc ]]; then + last_tag_base=$(echo $last_tag | sed 's/[a-zA-Z]*//g') + echo "last_tag_base=$last_tag_base" + corresponding_rc_tag=$(git tag | grep "${last_tag_base}-rc" | tail -n 1) + if [[ -n $corresponding_rc_tag ]]; then + echo "matching_rc_tag=$corresponding_rc_tag" >> $GITHUB_ENV + else + echo "CORRESPONDING_RC_TAG=No corresponding RC tag found" >> $GITHUB_ENV + fi + else + # If the latest tag is an rc tag, find the second to last rc tag with the same base number + last_tag_base=$(echo $last_tag | sed 's/-rc.*//') + + # Get the tags that match the given base pattern + matching_rc_tags=($(git tag | grep "${last_tag_base}-rc" | sort -V)) + matching_rc_tag=$(matching_rc_tags | tail -n 1) + echo "matching_rc_tag=$matching_rc_tag" >> $GITHUB_ENV + + if [[ ${#matching_rc_tags[@]} -eq 0 ]]; then + echo "No matching tags found for base: ${last_tag_base}-rc" + exit 1 + fi + + second_to_last_matching_rc_tag=${matching_rc_tags[-2]} + if [[ -n $second_to_last_matching_rc_tag ]]; then + echo "SECOND_TO_LAST_MATCHING_RC_TAG=$second_to_last_matching_rc_tag" >> $GITHUB_ENV + else + echo "SECOND_TO_LAST_MATCHING_RC_TAG=No second to last RC tag found" >> $GITHUB_ENV + fi + + echo "LAST_NON_RC_TAG=$non_pre_release_last_tag" >> $GITHUB_ENV + fi + + # # Debug: Print the counts of tags + # echo "Length of sorted_tags: $(echo "$sorted_tags" | wc -w)" + # echo "Length of pre_release_tags: ${#pre_release_tags[@]}" + # echo "Length of release_tags: ${#release_tags[@]}" + + # # Debug: Print the last and second to last tags + # echo "Last pre-release tag: $pre_release_last_tag" + # echo "Last non-pre-release tag: $non_pre_release_last_tag" + # echo "Second to last pre-release tag: $pre_release_second_to_last_tag" + # echo "Second to last non-pre-release tag: $non_pre_release_second_to_last_tag" + + # Print the tags in a logical order for understanding + echo "Last Tag: $last_tag" + echo "Pre-Release Tags:" + for tag in "${pre_release_tags[@]}"; do + echo $tag + done + + echo "Regular Release Tags:" + for tag in "${release_tags[@]}"; do + echo $tag + done + + echo "Second to last non-pre-release tag: $non_pre_release_second_to_last_tag" + + - name: Update the Kibot File with the Tags + run: | + if [ -n "${{ env.last_tag }}" ]; then + curl -o Diff_append.yaml https://raw.githubusercontent.com/42CrMo4/KiCad_Workflows/ki8Diff/.github/workflows/Diff_append.yaml + cat Diff_append.yaml >> *.kiplot.yaml + sed -i "s!<>!${{ env.last_tag }}!" *.kiplot.yaml + else + echo "No suitable tag found" + fi + if [ -n "${{ env.matching_rc_tag }}" ]; then + curl -o Diff_append.yaml https://raw.githubusercontent.com/42CrMo4/KiCad_Workflows/ki8Diff/.github/workflows/Diff_append.yaml + cat Diff_append.yaml >> *.kiplot.yaml + sed -i "s!<>!${{ env.matching_rc_tag }}!" *.kiplot.yaml + else + echo "No suitable rc-tag found" + fi + + - name: Assign variables from project.properties to Env variable + run: | + cat project.properties | egrep -v "^\s*(#|$)" >> $GITHUB_ENV + echo COMMIT=$(git rev-parse --short HEAD) >> $GITHUB_ENV + # https://kvz.io/blog/cat-a-file-without-the-comments.html + + - name: Update the Schematic with the git hash + run: | + sed -i "s!<>!Git-${{ env.COMMIT }}!" *.kicad_sch + sed -i "s!<>!${{ env.project_name }}!" *.kicad_sch + sed -i "s!<>!$(date +'%Y-%m-%d')!" *.kicad_sch + sed -i "s!<>!${{ env.ID }}!" *.kicad_sch + + - name: Update the PCBs with the git hash + run: | + sed -i "s!<>!Git-${{ env.COMMIT }}!" *.kicad_pcb + sed -i "s!<>!${{ env.project_name }}!" *.kicad_pcb + sed -i "s!<>!$(date +'%Y-%m-%d')!" *.kicad_pcb + sed -i "s!<>!${{ env.Website_link }}//${{ env.ID }}!" *.kicad_pcb + sed -i "s!<>!ID:${{ env.ID }}!" *.kicad_pcb + + - name: Update the KiPlot File with the git hash + run: | + sed -i "s!<>!Git-${{ env.COMMIT }}!" *.kiplot.yaml + sed -i "s!<>!${{ env.project_name }}!" *.kiplot.yaml + sed -i "s!<>!${{ env.ID }}!" *.kiplot.yaml + + - uses: INTI-CMNB/KiBot@v2_k8 + with: + # Required - kibot config file + config: config.kiplot.yaml + # optional - prefix to output defined in config + dir: Fabrication_temp + #skip: all + targets: print_front pcb_top_b pcb_bottom_b step print_sch interactive_bom bom_csv JLCPCB PCBWay + + - name: Rename the Schematic and PCB Raw Files + run: | + mv *.kicad_sch ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}.kicad_sch + mv *.kicad_pcb ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}.kicad_pcb + cp *.kicad_sch ${{ env.ID }}_${{ env.COMMIT }}.kicad_sch + cp *.kicad_pcb ${{ env.ID }}_${{ env.COMMIT }}.kicad_pcb + + - name: Retrieve results kicad_pcb with the git hash + uses: actions/upload-artifact@v4 + with: + name: ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}_Kicad_raw + path: '${{ env.ID }}_*.kicad_*' + + - name: Retrieve results + uses: actions/upload-artifact@v4 + with: + name: ${{ env.ID }}_${{ env.project_name }}_${{ env.COMMIT }}_Output + path: | + Fabrication_temp/ + + - uses: vimtor/action-zip@v1 + with: + files: Gerber/ + recursive: false + dest: ${{ env.ID_prefix }}${{ env.ID }}_${{ env.project_name }}_${{ github.ref_name }}_Gerber.zip + + - uses: ncipollo/release-action@v1 + with: + artifacts: "Fabrication_temp/*,Fabrication_temp/*/*, *.kicad_sch, *.kicad_pcb, *Gerber.zip" + bodyFile: "docs/release_note.md" + prerelease: ${{ needs.determine-release-type.outputs.release-type == 'rc' }} + token: ${{ secrets.GITHUB_TOKEN }} + + Archiv-md: + name: Archive & Renew Release Docs + runs-on: ubuntu-latest + needs: [Fabrication, determine-release-type] + if: needs.determine-release-type.outputs.release-type == 'release' + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Renaming Release note & checklist + copy the template + run: | + cd docs + mv release_note.md release_note_${{ github.ref_name }}.md + mv release_checklist.md release_checklist_${{ github.ref_name }}.md + cp release_template/release_note.md release_note.md + cp release_template/release_checklist.md release_checklist.md + + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + repository: . + branch: main + commit_message: Archive & Renew release docs \ No newline at end of file