Trigger weekly build #36
This file contains hidden or 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: Trigger weekly build | |
| on: | |
| schedule: | |
| # Runs every Monday | |
| - cron: '30 1 * * 2' | |
| workflow_dispatch: | |
| jobs: | |
| Triggerweeklybuild: | |
| runs-on: ubuntu-latest | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| WF_NAME: "weekly-build" | |
| steps: | |
| - name: Get last xunit.yml workflow run status triggered by push | |
| id: check-status | |
| run: | | |
| status=$(gh api repos/${GH_REPO}/actions/workflows/xunit.yml/runs \ | |
| --jq '.workflow_runs | map(select(.event == "push" and .head_branch == "main")) | first | .conclusion') | |
| echo "status=$status" >> $GITHUB_ENV | |
| - name: Check if weekly-build release exists | |
| id: check-release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| existing_release=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/releases/tags/weekly-build \ | |
| | jq -r '.id') | |
| if [ "$existing_release" != "null" ]; then | |
| echo "release_exists=true" >> $GITHUB_ENV | |
| else | |
| echo "release_exists=false" >> $GITHUB_ENV | |
| fi | |
| - name: Delete existing "weekly-build" release | |
| id: delete-release | |
| if: ${{ env.status == 'success' && env.release_exists == 'true' }} | |
| run: | | |
| existing_release=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/releases/tags/weekly-build \ | |
| | jq -r '.id') | |
| if [ "$existing_release" != "null" ]; then | |
| curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/releases/$existing_release | |
| fi | |
| - name: Delete existing "weekly-build" tag | |
| id: delete-tag | |
| if: ${{ steps.delete-release.outcome == 'success' }} | |
| run: | | |
| curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/git/refs/tags/weekly-build | |
| - name: Create new "weekly-build" release | |
| if: ${{ steps.delete-release.outcome == 'success' || env.release_exists == 'false' }} | |
| run: | | |
| current_date=$(date +'%Y-%m-%d') | |
| status=$(curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -d '{ | |
| "tag_name": "weekly-build", | |
| "target_commitish": "main", | |
| "name": "Weekly Build", | |
| "body": "Auto-generated weekly built on '"$current_date"'", | |
| "draft": false, | |
| "prerelease": true | |
| }' https://api.github.com/repos/${{ github.repository }}/releases) | |
| upload_url=$(echo $status | jq -r '.upload_url') | |
| echo "upload_url=$upload_url" >> $GITHUB_ENV | |
| echo $status | |
| - name: Set Asset Name | |
| id: set-asset-name | |
| run: | | |
| date=$(date +'%Y-%m-%d') | |
| echo "zipfilename=TameMyCerts_community_${date}.zip" >> $GITHUB_ENV | |
| - name: Trigger target workflow | |
| run: | | |
| curl -X POST -H "Accept: application/vnd.github.v3+json" \ | |
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/workflows/uploadreleasefile.yml/dispatches \ | |
| -d '{"ref":"main","inputs":{"upload_url":"${{ env.upload_url }}","zipfilename":"${{ env.zipfilename }}","versiontag":"weekly-build"}}' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Complete the weekly build process | |
| run: echo "Weekly build completed!" |