github.com/hashicorp/packer@v1.14.3/.github/workflows/nightly-release.yml (about) 1 # 2 # This GitHub action triggers a fresh set of Packer builds 3 # and publishes them to GitHub Releases under the `nightly` tag. 4 # Note that artifacts available via GitHub Releases are not codesigned or notarized. 5 # Failures are reported to slack. 6 # 7 8 name: Nightly Release 9 10 on: 11 schedule: 12 # Runs against the default branch every day at midnight 13 - cron: "0 0 * * *" 14 workflow_dispatch: 15 16 permissions: 17 contents: write 18 19 jobs: 20 # Build a fresh set of artifacts 21 build-artifacts: 22 uses: hashicorp/packer/.github/workflows/build.yml@main 23 github-release: 24 needs: build-artifacts 25 runs-on: ubuntu-latest 26 steps: 27 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 28 - name: Download built artifacts 29 uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 30 with: 31 path: out/ 32 # Set BUILD_OUTPUT_LIST to out\<project>-<version>.<fileext>\*,out\... 33 # This is needed to attach the build artifacts to the GitHub Release 34 - name: Set BUILD_OUTPUT_LIST 35 run: | 36 echo "$(ls -xm1 out/)" > tmp.txt 37 cat tmp.txt | sed 's:.*:out/&/*:' > tmp2.txt 38 echo "BUILD_OUTPUT_LIST=$(cat tmp2.txt | tr '\n' ',' | perl -ple 'chop')" >> $GITHUB_ENV 39 rm -rf tmp.txt && rm -rf tmp2.txt 40 - name: Advance nightly tag 41 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 42 with: 43 github-token: ${{ secrets.GITHUB_TOKEN }} 44 script: | 45 try { 46 await github.rest.git.deleteRef({ 47 owner: context.repo.owner, 48 repo: context.repo.repo, 49 ref: "tags/nightly" 50 }) 51 } catch (e) { 52 console.log("Warning: The nightly tag doesn't exist yet, so there's nothing to do. Trace: " + e) 53 } 54 await github.rest.git.createRef({ 55 owner: context.repo.owner, 56 repo: context.repo.repo, 57 ref: "refs/tags/nightly", 58 sha: context.sha 59 }) 60 # This will create a new GitHub Release called `nightly` 61 # If a release with this name already exists, it will overwrite the existing data 62 - name: Create a nightly GitHub prerelease 63 id: create_prerelease 64 continue-on-error: true 65 uses: ncipollo/release-action@cdcc88a9acf3ca41c16c37bb7d21b9ad48560d87 # v1.15.0 66 with: 67 name: nightly 68 artifacts: "${{ env.BUILD_OUTPUT_LIST }}" 69 tag: nightly 70 bodyFile: ".github/workflows/nightly-release-readme.md" 71 prerelease: true 72 allowUpdates: true 73 removeArtifacts: true 74 draft: false 75 token: ${{ secrets.GITHUB_TOKEN }} 76 - name: Store GitHub Release ID 77 if: steps.create_prerelease.outcome == 'success' 78 run: | 79 echo "prerelease_id=${{ steps.create_prerelease.outputs.id }}" >> $GITHUB_ENV 80 - name: Sleep before retry 81 id: sleep_before_retry 82 if: steps.create_prerelease.outcome == 'failure' 83 run : sleep 30m 84 shell: bash 85 - name: Retry failed nightly GitHub prerelease 86 id: create_prerelease_retry 87 if: steps.create_prerelease.outcome == 'failure' 88 uses: ncipollo/release-action@cdcc88a9acf3ca41c16c37bb7d21b9ad48560d87 # v1.15.0 89 with: 90 name: nightly 91 artifacts: "${{ env.BUILD_OUTPUT_LIST }}" 92 tag: nightly 93 bodyFile: ".github/workflows/nightly-release-readme.md" 94 prerelease: true 95 allowUpdates: true 96 removeArtifacts: true 97 draft: false 98 token: ${{ secrets.GITHUB_TOKEN }} 99 - name: Store Updated GitHub Release ID 100 if: steps.create_prerelease_retry.outcome == 'success' 101 run: | 102 echo "prerelease_id=${{ steps.create_prerelease_retry.outputs.id }}" >> $GITHUB_ENV 103 - name: Publish nightly GitHub prerelease 104 uses: eregon/publish-release@01df127f5e9a3c26935118e22e738d95b59d10ce # v1.0.6 105 env: 106 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 107 with: 108 release_id: ${{ env.prerelease_id }} 109 # Send a slack notification if either job defined above fails 110 slack-notify: 111 permissions: 112 contents: none 113 needs: 114 - build-artifacts 115 - github-release 116 if: always() && (needs.build-artifacts.result == 'failure' || needs.github-release.result == 'failure') 117 runs-on: ubuntu-latest 118 steps: 119 - name: Send slack notification on failure 120 uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0 121 with: 122 payload: | 123 { 124 "text": ":alert: Packer Nightly Release *FAILED* :alert:", 125 "attachments": [ 126 { 127 "color": "#C41E3A", 128 "blocks": [ 129 { 130 "type": "section", 131 "text": { 132 "type": "mrkdwn", 133 "text": "Branch: `${{ github.ref_name }}`\nRef: ${{ github.sha }}\nWorkflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" 134 } 135 } 136 ] 137 } 138 ] 139 } 140 env: 141 SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} 142 SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK