diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..24f94bb --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,69 @@ +name: release + +on: + schedule: + - cron: '*/10 * * * *' # schedule nightly build daily at midnight UTC + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Ensure workspace ownership + run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE + + - name: Check out code + uses: actions/checkout@v3 + + - name: Prepare release body + run: | + if [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_REF == refs/tags/* ]]; then + RELEASE_TAG=${GITHUB_REF#refs/tags/} + if [[ $RELEASE_TAG == 'nightly' ]]; then + PRERELEASE=true + else + PRERELEASE=false + fi + echo "Workflow triggered by tag: $RELEASE_TAG" + else + RELEASE_TAG=nightly + PRERELEASE=true + echo "Workflow triggered by schedule" + fi + echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV + echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV + RELEASE_DATETIME=$(date --rfc-3339=seconds) + cat < release_template.md + Release $RELEASE_TAG created from $GITHUB_SHA at $RELEASE_DATETIME + EOF + envsubst < release_template.md > release_body.md + + - name: Move the existing mutable tag + # https://github.com/softprops/action-gh-release/issues/171 + run: | + if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then + # Determine if a given tag exists and matches a specific Git commit. + if [ "$(git rev-parse -q --verify "refs/tags/$RELEASE_TAG")" = "$GITHUB_SHA" ]; then + echo "mutalbe tag $RELEASE_TAG exists and matchs $GITHUB_SHA" + echo "MOVED_MUTABLE_TAG=false" >> $GITHUB_ENV + else + git tag -f $RELEASE_TAG $GITHUB_SHA + git push -f origin $RELEASE_TAG:refs/tags/$RELEASE_TAG + echo "created/moved mutalbe tag $RELEASE_TAG to $GITHUB_SHA" + echo "MOVED_MUTABLE_TAG=true" >> $GITHUB_ENV + fi + fi + + - name: Build source tarball + run: git archive --format=tar HEAD | gzip > archive.tgz + + - name: Create or overwrite a release + # https://github.com/actions/upload-release-asset has been replaced by https://github.com/softprops/action-gh-release + uses: softprops/action-gh-release@v1 + with: + token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable + prerelease: ${{ env.PRERELEASE }} + tag_name: ${{ env.RELEASE_TAG }} + # The body field does not support environment variable substitution directly. + body_path: release_body.md + files: | + *.tgz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6a50033..fca744b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,6 @@ name: release on: - schedule: - - cron: '*/10 * * * *' # schedule nightly build daily at midnight UTC push: tags: - "v*.*.*" # normal release @@ -41,27 +39,6 @@ jobs: EOF envsubst < release_template.md > release_body.md - - name: Move the existing mutable tag - # https://github.com/softprops/action-gh-release/issues/171 - run: | - if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then - # Determine if a given tag exists and matches a specific Git commit. - if [ "$(git rev-parse -q --verify "refs/tags/$RELEASE_TAG")" = "$GITHUB_SHA" ]; then - echo "mutalbe tag $RELEASE_TAG exists and matchs $GITHUB_SHA" - echo "MOVED_MUTABLE_TAG=false" >> $GITHUB_ENV - else - git tag -f $RELEASE_TAG $GITHUB_SHA - git push -f origin $RELEASE_TAG:refs/tags/$RELEASE_TAG - echo "created/moved mutalbe tag $RELEASE_TAG to $GITHUB_SHA" - echo "MOVED_MUTABLE_TAG=true" >> $GITHUB_ENV - fi - fi - - - name: Exits the workflow if tag has been moved. - if: ${{ env.MOVED_MUTABLE_TAG == 'true' }} - # Exits the workflow if tag has been moved since creating/moving triggers another run of this workflow. - run: exit 0 # Exits the workflow with success - - name: Build source tarball run: git archive --format=tar HEAD | gzip > archive.tgz