Publish Release #40
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
name: Publish Release | |
on: | |
workflow_dispatch: | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Variable Gathering | |
id: gathervars | |
run: | | |
NOT_PREVIOUSLY_PUBLISHED=0 | |
# get a current BUILD_DATE | |
VERSION=$(jq -r '.version' ./package.json) | |
echo "BUILD_DATE=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
# setting tags | |
if echo "$VERSION" | grep -q "beta"; then | |
echo "TAGS=ghcr.io/${{ github.repository }}:beta, ghcr.io/${{ github.repository }}:$VERSION, ghcr.io/${{ github.repository }}:latest" >> $GITHUB_ENV | |
else | |
echo "TAGS=ghcr.io/${{ github.repository }}:release, ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:$VERSION" >> $GITHUB_ENV | |
fi | |
echo "PRIMARY_TAG=latest" >> $GITHUB_ENV | |
# check if version has already been published | |
$(docker manifest inspect ghcr.io/${{ github.repository }}:$VERSION > /dev/null) || NOT_PREVIOUSLY_PUBLISHED=1 | |
echo "NOT_PREVIOUSLY_PUBLISHED=$NOT_PREVIOUSLY_PUBLISHED" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker Image | |
uses: docker/build-push-action@v4 | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
with: | |
build-args: | | |
BUILD_DATE=${{ env.BUILD_DATE }} | |
VERSION=${{ env.VERSION }} | |
context: ./docker/production | |
tags: | | |
${{ env.TAGS }} | |
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 | |
push: true | |
- name: Extract build out of docker image | |
uses: shrink/actions-docker-extract@v2 | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
id: extract | |
with: | |
image: ghcr.io/${{ github.repository }}:${{ env.PRIMARY_TAG }} | |
path: web | |
- name: create release asset | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
run: | | |
cd "${{ steps.extract.outputs.destination }}" | |
7z a headscale-ui.zip web | |
- name: Create Draft Release | |
id: create_release | |
uses: actions/create-release@v1 | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: headscale-ui | |
draft: true | |
prerelease: false | |
- name: upload asset to releases | |
uses: actions/[email protected] | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ steps.extract.outputs.destination }}/headscale-ui.zip | |
asset_name: headscale-ui.zip | |
asset_content_type: application/zip | |
- name: publish release | |
uses: eregon/publish-release@v1 | |
if: ${{ env.NOT_PREVIOUSLY_PUBLISHED != 0 }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
release_id: ${{ steps.create_release.outputs.id }} |