Merge pull request #27 from Kerosene-Labs/update-workflow #13
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: SDLC | |
on: | |
release: | |
types: | |
- published | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
actions: read | |
security-events: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
server-id: github | |
settings-path: ${{ github.workspace }} | |
- name: Install Node Dependencies | |
run: cd src/main/frontend && npm i | |
- name: Determine PROJECT_VERSION | |
id: set-project-version | |
run: | | |
if [ "${{ github.event_name }}" = "release" ]; then | |
echo "PROJECT_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
else | |
echo "PROJECT_VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
fi | |
- name: Show PROJECT_VERSION | |
run: echo "PROJECT_VERSION is $PROJECT_VERSION" | |
- name: Build with Maven | |
run: mvn -B package --file pom.xml -Dproject.version=${PROJECT_VERSION} | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: app | |
path: | | |
target/billtracker-${{ env.PROJECT_VERSION }}.jar | |
- name: Initialize CodeQL | |
uses: github/codeql-action/init@v3 | |
with: | |
languages: 'java,javascript' # Specify your project's languages | |
- name: CodeQL Autobuild | |
uses: github/codeql-action/autobuild@v3 | |
- name: Perform CodeQL Analysis | |
uses: github/codeql-action/analyze@v3 | |
with: | |
category: '/language-security-and-quality' # Customize category if needed | |
publish_maven: | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
- name: Install dependencies | |
run: cd src/main/frontend && npm i | |
- uses: actions/download-artifact@v4 | |
with: | |
name: app | |
- name: Determine PROJECT_VERSION | |
id: set-project-version | |
run: | | |
if [ "${{ github.event_name }}" = "release" ]; then | |
echo "PROJECT_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
else | |
echo "PROJECT_VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
fi | |
- name: Publish to GitHub Packages Apache Maven | |
run: mvn deploy -s ./settings.xml -Dgithub.token=${{ secrets.ACCESS_TOKEN }} -Dproject.version=${PROJECT_VERSION} | |
publish_container: | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Install dependencies | |
run: cd src/main/frontend && npm i | |
- uses: actions/download-artifact@v4 | |
with: | |
name: app | |
- name: Determine PROJECT_VERSION | |
id: set-project-version | |
run: | | |
if [ "${{ github.event_name }}" = "release" ]; then | |
echo "PROJECT_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
else | |
echo "PROJECT_VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
fi | |
- name: Build Container Image | |
run: docker build . -t ghcr.io/kerosene-labs/billtracker:${{ github.ref_name }} --build-arg PROJECT_VERSION=${PROJECT_VERSION} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.ACCESS_TOKEN }} | |
- name: Push Container Image | |
run: docker push ghcr.io/kerosene-labs/billtracker:${{ github.ref_name }} | |
deploy: | |
# if: github.event_name == 'release' | |
needs: | |
- publish_container | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ github.event_name == 'release' && 'production' || 'development' }} | |
steps: | |
- name: Setup SSH Agent | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{secrets.DEPLOY_PRIVATE_KEY}} | |
- uses: actions/download-artifact@v4 | |
with: | |
name: build | |
- name: Transfer artifact to target | |
run: ssh ${{ secrets.DEPLOY_PRIVATE_KEY }} "cd ${{ secrets.TOFU_PATH }} && tofu apply -auto-approve" |