Skip to content

Nightly Release

Nightly Release #6

name: Nightly Release
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
release:
name: Create Nightly Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: devel
- name: Set Version as Date
id: version
run: echo "APP_VERSION=nightly-build:$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Get Existing Release
id: get_release
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { data: releases } = await github.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const nightlyRelease = releases.find(release => release.tag_name === 'nightly');
if (nightlyRelease) {
core.setOutput('upload_url', nightlyRelease.upload_url);
core.setOutput('release_id', nightlyRelease.id);
}
- name: Create Release if Not Exists
if: steps.get_release.outputs.upload_url == ''
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "nightly"
release_name: "Nightly Build"
draft: false
prerelease: true
continue-on-error: true
- name: Set Upload URL
if: steps.get_release.outputs.upload_url != ''
run: echo "UPLOAD_URL=${{ steps.get_release.outputs.upload_url }}" >> $GITHUB_ENV
- name: Set Upload URL from New Release
if: steps.create_release.outputs.upload_url != ''
run: echo "UPLOAD_URL=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_ENV
- name: Build Go Application
run: |
mkdir -p ${{ github.workspace }}/packagelock
APP_VERSION=${{ env.APP_VERSION }}
CGO_ENABLED=0 GOOS=linux go build -ldflags "-X 'main.AppVersion=$APP_VERSION'" -o ${{ github.workspace }}/packagelock
- name: Create Release Archive
run: |
mkdir -p release
cp -r ${{ github.workspace }}/packagelock ./release/packagelock
tar -czvf release/packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz -C release packagelock
- name: Calculate Checksum
run: |
md5sum ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz | cut -f 1 -d " " > ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz.md5
- name: Upload Release Tarball
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz
asset_name: packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz
asset_content_type: application/gzip
- name: Upload Checksum
id: upload-checksum-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz.md5
asset_name: packagelock-${{ env.APP_VERSION }}-linux-amd64-nightly.tar.gz.md5
asset_content_type: text/plain