Skip to content

Nightly

Nightly #480

Workflow file for this run

on:
schedule:
- cron: '0 0 * * *'
name: Nightly
defaults:
run:
shell: bash --noprofile --norc -euo pipefail {0}
jobs:
deploy:
name: Deploy
runs-on: ubuntu-18.04
outputs:
deployed: "${{ steps.check-changes.outputs.changed == 'true' && job.status == 'success' }}"
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v12
- uses: cachix/cachix-action@v10
with:
name: sos21-backend
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Check changes
id: check-changes
run: |
git pull --tags
last_nightly=$(git tag --list --sort=taggerdate 'nightly-*' | tail -n 1)
if [ -z "$last_nightly" ]; then
echo "::set-output name=changed::true"
exit
fi
git diff --exit-code "$last_nightly" \
&& echo "::set-output name=changed::false" \
|| echo "::set-output name=changed::true"
- name: Create ssh private key file
if: ${{ steps.check-changes.outputs.changed == 'true' }}
env:
SSH_PRIVATE_KEY: "${{ secrets.SSH_PRIVATE_KEY }}"
run: |
touch ./ssh_private_key
chmod 600 ./ssh_private_key
echo "$SSH_PRIVATE_KEY" > ./ssh_private_key
- name: Create NixOS configuration from secrets
env:
ADMINISTRATOR_EMAIL: "${{ secrets.ADMINISTRATOR_EMAIL }}"
run: |
cat << EOS > ./configuration.nix
{ ... }:
{
services.sos21-api-server = {
administratorEmail = "$ADMINISTRATOR_EMAIL";
};
}
EOS
- name: Deploy
if: ${{ steps.check-changes.outputs.changed == 'true' }}
uses: sohosai/sos-backend-infrastructure/actions/deploy-staging@main
with:
target: api.nightly.online.sohosai.com
ssh_private_key: ./ssh_private_key
configurations: |
./nix/deployment/nightly.nix
./configuration.nix
- name: Delete ssh private key file
if: always()
run: rm -f ./ssh_private_key
tag:
name: Tag
runs-on: ubuntu-18.04
needs: deploy
if: needs.deploy.outputs.deployed == 'true'
steps:
- uses: actions/checkout@v2
with:
# GITHUB_TOKEN user cannot trigger another workflow
token: "${{ secrets.TAGGER_PAT }}"
- name: git tag
run: |
tag_name=$(date +'nightly-%Y-%m-%d')
git tag "$tag_name"
git push --tags