Nightly Release #4
This file contains 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
# | |
# Copyright 2022 The GUAC Authors. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# This workflow requires a GitHub Personal Access Token named PAT_NIGHTLY_RELEASE | |
# to work. The token must have read/write permissions on Contents. | |
# This is becuase the inbuilt GITHUB_TOKEN will not create a new workflow run - | |
# see https://docs.github.com/en/actions/using-workflows/triggering-a-workflow | |
name: Nightly Release | |
on: | |
workflow_dispatch: # testing only, trigger manually to test it works | |
schedule: | |
- cron: '44 4 * * *' #UTC | |
env: | |
NIGHTLY_RELEASE_TAG: v0-nightly #goreleaser enforces semver on tags | |
# Note that the container tag (per .goreleaser-nightly.yaml) | |
# is simply 'nightly' without semver prefix | |
jobs: | |
refresh-nightly-tag: | |
runs-on: ubuntu-latest | |
name: trigger nightly build | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # tag=v3 | |
- name: refresh nightly tag | |
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 | |
with: | |
github-token: ${{ secrets.PAT_NIGHTLY_RELEASE }} # must use PAT here or the release workflow won't be triggered | |
script: | | |
const { owner, repo } = context.repo | |
try { | |
console.log('Deleting release') | |
const { data: { id } } = await github.rest.repos.getReleaseByTag({ | |
owner, | |
repo, | |
tag: "${{ env.NIGHTLY_RELEASE_TAG }}" | |
}) | |
const result = await github.rest.repos.deleteRelease({ | |
owner, | |
repo, | |
release_id: id | |
}) | |
console.log(result) | |
} catch (error) { | |
// ignore error in case release doesn't exist | |
console.log(error) | |
} | |
try { | |
console.log('Deleting tag') | |
const result = github.rest.git.deleteRef({ | |
owner: owner, | |
repo: repo, | |
ref: "tags/${{ env.NIGHTLY_RELEASE_TAG }}" | |
}) | |
console.log(result) | |
} catch (error) { | |
// ignore error in case tag doesn't exist | |
console.log(error) | |
} | |
// sleep to make sure the delete ops above are propagated in github | |
await new Promise(r => setTimeout(r, 3000)); | |
console.log('Creating tag to trigger build') | |
const result = github.rest.git.createRef({ | |
owner: owner, | |
repo: repo, | |
ref: "refs/tags/${{ env.NIGHTLY_RELEASE_TAG }}", | |
sha: context.sha | |
}) | |
console.log(result) |