|
| 1 | +name: Nightly Builds |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # * is a special character in YAML so you have to quote this string |
| 6 | + - cron: '0 0 * * *' |
| 7 | + |
| 8 | +jobs: |
| 9 | + create-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + outputs: |
| 13 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 14 | + date: ${{ steps.current_time_underscores.outputs.formattedTime }} |
| 15 | + activity_check: ${{ env.GHA_REPO_ALIVE }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Activity check |
| 19 | + run: | |
| 20 | + : |
| 21 | + # Based off https://github.community/t/trigger-workflow-if-there-is-commit-in-last-24-hours/17074/3 |
| 22 | + curl -sL https://api.github.com/repos/$GITHUB_REPOSITORY/commits | jq -r '[.[]][0]' > $HOME/commit.json |
| 23 | + date="$(jq -r '.commit.committer.date' $HOME/commit.json)" |
| 24 | + timestamp=$(date --utc -d "$date" +%s) |
| 25 | + author="$(jq -r '.commit.committer.name' $HOME/commit.json)" |
| 26 | + url="$(jq -r '.html_url' $HOME/commit.json)" |
| 27 | + days=$(( ( $(date --utc +%s) - $timestamp ) / 86400 )) |
| 28 | + rm -f $HOME/commit.json |
| 29 | + echo "Repository activity : $timestamp $author $url" |
| 30 | + alive=0 |
| 31 | + if [ "${{ github.event_name }}" == "repository_dispatch" ]; then |
| 32 | + echo "[WARNING] Ignoring activity limits : workflow triggered manually" |
| 33 | + alive=1 |
| 34 | + else |
| 35 | + if [ $days -lt 1 ]; then |
| 36 | + echo Repository active : $days days |
| 37 | + alive=1 |
| 38 | + else |
| 39 | + echo "[WARNING] Repository not updated : event<${{ github.event_name }}> not allowed to modify stale repository" |
| 40 | + fi |
| 41 | + fi |
| 42 | + if [ $alive -eq 1 ]; then |
| 43 | + echo ::set-env name=GHA_REPO_ALIVE::true |
| 44 | + fi |
| 45 | + shell: bash |
| 46 | + |
| 47 | + - name: Get current time |
| 48 | + uses: 1466587594/get-current-time@v2 |
| 49 | + id: current_time_dashes |
| 50 | + with: |
| 51 | + format: YYYY-MM-DD |
| 52 | + |
| 53 | + - name: Get current time with underscores |
| 54 | + uses: 1466587594/get-current-time@v2 |
| 55 | + id: current_time_underscores |
| 56 | + with: |
| 57 | + format: YYYY_MM_DD |
| 58 | + |
| 59 | + - name: Create release |
| 60 | + if: env.GHA_REPO_ALIVE == 'true' |
| 61 | + id: create_release |
| 62 | + uses: actions/create-release@v1 |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + with: |
| 66 | + tag_name: nightly-${{ steps.current_time_dashes.outputs.formattedTime }} |
| 67 | + release_name: Nightly ${{ steps.current_time_dashes.outputs.formattedTime }} |
| 68 | + prerelease: true |
| 69 | + |
| 70 | + upload-release: |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: create-release |
| 73 | + if: needs.create-release.outputs.activity_check == 'true' |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v2 |
| 76 | + - name: Use Node.js 14.x |
| 77 | + uses: actions/setup-node@v1 |
| 78 | + with: |
| 79 | + node-version: 14.x |
| 80 | + - run: npm install |
| 81 | + |
| 82 | + - name: Build and Package Release |
| 83 | + run: | |
| 84 | + npm run package |
| 85 | +
|
| 86 | + - name: Release Extension Package |
| 87 | + uses: actions/upload-release-asset@v1 |
| 88 | + env: |
| 89 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + with: |
| 91 | + upload_url: ${{ needs.create-release.outputs.upload_url }} |
| 92 | + asset_path: ./extension.fplx |
| 93 | + asset_name: analytics-ext_nightly_${{ needs.create-release.outputs.date }}.zip |
| 94 | + asset_content_type: application/zip |
| 95 | + |
0 commit comments