Build and run tests in a dev container #7
Workflow file for this run
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: Dev Container | |
permissions: | |
contents: read | |
packages: write | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '.devcontainer/**' | |
- '.github/workflows/devcontainer.yml' | |
pull_request: | |
branches: | |
- main | |
paths: | |
- '.devcontainer/**' | |
- '.github/workflows/devcontainer.yml' | |
jobs: | |
publish-devcontainer: | |
name: Publish Dev Container | |
runs-on: ubuntu-latest | |
steps: | |
- name: Initialize repository | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: '.devcontainer/Dockerfile' | |
submodules: false | |
- name: Define variables | |
id: vars | |
run: | | |
tag=`date +%s` | |
image_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/compiler-project/devcontainer" | |
echo "image-name=$image_name" >> $GITHUB_OUTPUT | |
echo "image-name-tag=$image_name:$tag" >> $GITHUB_OUTPUT | |
- name: Build image | |
run: docker build -t ${{ steps.vars.outputs.image-name-tag }} -f .devcontainer/Dockerfile . | |
- name: Login to registry | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: docker login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io | |
- name: Push image | |
run: docker push ${{ steps.vars.outputs.image-name-tag }} | |
- name: Push image as latest | |
if: github.event_name == 'push' | |
run: | | |
docker tag ${{ steps.vars.outputs.image-name-tag }} ${{ steps.vars.outputs.image-name }}:latest | |
docker push ${{ steps.vars.outputs.image-name }}:latest |