Build and Release #397
This file contains hidden or 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: Build and Release | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| jobs: | |
| buildAndRelease: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| # needed for creating a release | |
| contents: write | |
| # needed for pushing docker image | |
| attestations: write | |
| id-token: write | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up jq | |
| run: | | |
| sudo apt-get update && sudo apt-get install jq -y | |
| - name: Set up Name and Version | |
| id: releases | |
| run: | | |
| NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/} | |
| THIS_REPO=https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest | |
| TARGET_REPO=https://api.github.com/repos/coder/code-server/releases/latest | |
| CURRENT_VERSION=$(curl -s $THIS_REPO | jq -r '.tag_name // empty') | |
| TARGET_VERSION=$(curl -s $TARGET_REPO | jq -r '.tag_name // empty') | |
| RELEASE_URL=$(curl -s $TARGET_REPO | jq -r '.html_url') | |
| echo "VERSION=${TARGET_VERSION}" >> $GITHUB_ENV | |
| echo "NAME=${NAME}" >> $GITHUB_ENV | |
| echo "url=${RELEASE_URL}" >> $GITHUB_OUTPUT | |
| echo "current=${CURRENT_VERSION}" >> $GITHUB_OUTPUT | |
| echo "target=${TARGET_VERSION}" >> $GITHUB_OUTPUT | |
| echo Using NAME=$NAME, TARGET_VERSION=$TARGET_VERSION, CURRENT_VERSION=$CURRENT_VERSION, RELEASE_URL=$RELEASE_URL | |
| - name: Set up Docker | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build Docker image | |
| env: | |
| VERSION: ${{ steps.releases.outputs.target }} | |
| run: | | |
| docker pull docker.io/fedora:latest | |
| docker build --build-arg VERSION=$VERSION --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` -t ghcr.io/${{ github.repository_owner }}/$NAME:$VERSION . | |
| docker tag ghcr.io/${{ github.repository_owner }}/$NAME:$VERSION ghcr.io/${{ github.repository_owner }}/$NAME:latest | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| if: steps.releases.outputs.current != steps.releases.outputs.target | |
| env: | |
| VERSION: ${{ steps.releases.outputs.target }} | |
| with: | |
| name: Update to ${{ steps.releases.outputs.target }} | |
| tag_name: ${{ steps.releases.outputs.target }} | |
| body: See release notes [here](${{ steps.releases.outputs.url }}) | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| if: steps.releases.outputs.current != steps.releases.outputs.target | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Push Docker image | |
| if: steps.releases.outputs.current != steps.releases.outputs.target | |
| env: | |
| VERSION: ${{ steps.releases.outputs.target }} | |
| run: | | |
| docker push ghcr.io/${{ github.repository_owner }}/$NAME:$VERSION | |
| docker push ghcr.io/${{ github.repository_owner }}/$NAME:latest |