Skip to content

Commit

Permalink
Jobs archiving (#854)
Browse files Browse the repository at this point in the history
* Jobs archiving after 2 months instead of deleting
  • Loading branch information
milosyuki authored Jul 13, 2023
1 parent 1848262 commit 79b65a1
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 55 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/update-jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Update Jobs

on:
schedule:
- cron: "0 0 * * *" # This will run the workflow every day at midnight

jobs:
update-jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
.yarn/cache
.yarn/install-state.gz
.eslintcache
**/tsconfig.tsbuildinfo
**/.types/**
**/.types-*/**
key: build-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
build-cache-
- name: Install dependencies
run: yarn

- name: Run update-jobs script
run: yarn update-jobs

- name: Commit and push changes
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git checkout dev
git checkout -b update-jobs
git add .
git commit -m "Update jobs"
git push origin update-jobs
- name: pull-request
uses: repo-sync/pull-request@v2
with:
pr_title: "Jobs archiving PR"
pr_body: |
## How to approve and merge this pull request
As a content contributor, follow these steps to review, approve, and merge this pull request:
- [ ] 1. Review the changes made in this pull request by looking at the "Files changed" tab. Make sure everything looks correct and as expected.
- [ ] 2. Visit the live preview of the changes at [https://starknet-website-dev.vercel.app/](https://starknet-website-dev.vercel.app/). Ensure the changes are properly implemented and everything is working as expected.
- [ ] 3. If you are satisfied with the changes, click on the "Review changes" button (usually green) at the top of the pull request page.
- [ ] 4. In the review summary dialog, select "Approve" and click on "Submit review."
- [ ] 5. Click on "Confirm merge" to finalize the process. The changes will be applied to the production branch, and [starknet.io](http://starknet.io) will be updated within a few minutes.
If you are unsure about merging something or need any assistance, please ping a developer to double check.
pr_allow_empty: false
pr_label: "auto-pr"
source_branch: "update-jobs"
destination_branch: "dev"
github_token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion _data/jobs/1f73f99c-b264-4bfa-a8bb-6046d30c550f.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ job:
type: full_time
location: tel_aviv_remote
role: Blockchain Contract
published_at: 2023-06-19T09:08:00.000Z
published_at: 2023-02-19T08:22:08.615Z
status: active
archive_after: 2
2 changes: 2 additions & 0 deletions _data/jobs/69447136-1854-49d5-8808-5dddb902f94f.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ job:
location: online_remote
apply_url: https://boards.greenhouse.io/paradigm62/jobs/4495567004
published_at: 2023-06-19T08:21:42.776Z
status: active
archive_after: 2
2 changes: 2 additions & 0 deletions _data/jobs/7027c387-6558-475e-97e6-6631442a2bd1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ job:
type: full_time
location: online_remote
published_at: 2023-06-19T08:22:08.615Z
status: active
archive_after: 2
2 changes: 2 additions & 0 deletions _data/jobs/job1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ job:
mentality.
apply_url: mailto:[email protected]
published_at: 2023-06-07T09:22:26.814Z
status: active
archive_after: 2
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"typecheck:watch": "tsc -b -w",
"cms": "yarn workspace @starknet-io/netlify-cms dev",
"data": "yarn workspace @starknet-io/cms-scripts update-dynamic-data",
"update-jobs": "yarn workspace @starknet-io/cms-scripts update-jobs",
"update:algolia": "yarn workspace @starknet-io/cms-scripts update-algolia-index",
"starknet-summit": "yarn workspace @starknet-io/starknet-summit dev",
"storybook": "yarn workspace @starknet-io/storybook storybook",
Expand Down
61 changes: 55 additions & 6 deletions workspaces/cms-config/src/collections/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,66 @@ export const jobsCollectionConfig = {
create: true,
format: "yml",
summary: "{{job.title}}",
view_filters: [
{
field: 'status',
label: 'Active',
pattern: 'active'
},
{
field: 'status',
label: 'Archived',
pattern: 'archived'
},
],
fields: [
{
name: "id",
label: "id",
widget: "uuid",
},
{
label: "Published at",
name: "published_at",
widget: "datetime",
},
{
label: "Status",
name: "status",
hint: "If set to Active, update the 'Published at' date to be not older than the value from 'Archive after' field",
widget: "select",
options: [
{
label: "Active",
value: "active",
},
{
label: "Archived",
value: "archived",
},
]
},
{
label: "Archive after",
name: "archive_after",
widget: "select",
options: [
{
label: "1 month",
value: 1,
},
{
label: "2 months",
value: 2,
},
{
label: "3 months",
value: 3,
},
],
default: "2 months",
crowdin: false
},
{
name: "contact",
label: "Contact",
Expand Down Expand Up @@ -161,11 +215,6 @@ export const jobsCollectionConfig = {
crowdin: false
},
],
},
{
label: "Published at",
name: "published_at",
widget: "datetime",
},
}
],
} satisfies CmsCollection;
1 change: 1 addition & 0 deletions workspaces/cms-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"update-algolia-index": "vite-node src/algolia.ts",
"update-dynamic-data": "vite-node src/index.ts",
"update-jobs": "vite-node src/jobs-update.ts",
"pre-crowdin": "vite-node src/pre-crowdin.ts",
"build": "tsc"
},
Expand Down
31 changes: 2 additions & 29 deletions workspaces/cms-scripts/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path";
import fs from "fs/promises";
import YAML from "yaml";
import { locales } from "@starknet-io/cms-data/src/i18n/config";
import { scandir, yaml } from "./utils";
import { DefaultLogFields } from "simple-git";
Expand Down Expand Up @@ -454,7 +455,6 @@ export async function getSimpleData<T = {}>(
const sourceFilepath = path.join("_data", resourceName, filename);
const sourceData = await yaml(sourceFilepath);
const data = await translateFile(locale, resourceName, filename);

const defaultLocaleTitle = sourceData.title ?? sourceData.name;

const slug = defaultLocaleTitle ? slugify(defaultLocaleTitle) : undefined;
Expand Down Expand Up @@ -548,33 +548,6 @@ export function updateBlocks(pages: PagesData, posts: PostsData) {
}
}

export async function updateJobs() {
const resourceName = "jobs";
const filenames = await fs.readdir(`_data/${resourceName}`);

for (const filename of filenames) {
const filepath = path.join("_data", resourceName, filename);

const data = await yaml(filepath);

const isOlderThanTwoMonths = (dateString: string) => {
const date = new Date(dateString);
const today = new Date();
today.setMonth(today.getMonth() - 2);
return date < today;
}
const isOlder = isOlderThanTwoMonths(data.published_at);
if (isOlder) {
try {
await fs.unlink(filepath);
} catch (err) {
console.error(err);
}
}

}
}

export function handleLink(
locale: string,
link: any,
Expand Down Expand Up @@ -620,4 +593,4 @@ export function handleLink(
}

return newLink;
}
}
3 changes: 1 addition & 2 deletions workspaces/cms-scripts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
getTutorials,
handleLink,
updateBlocks,
updateJobs
} from "./data";
import { translateFile } from "./crowdin";

Expand Down Expand Up @@ -131,6 +130,7 @@ const simpleDataTypes = [
await getSimpleData("events"),
await getSimpleData("topics"),
await getSimpleData("roadmap-versions"),
await getSimpleData("jobs"),
];

for (const simpleData of simpleDataTypes) {
Expand Down Expand Up @@ -190,7 +190,6 @@ const pages = await getPages();
const tutorials = await getTutorials();

updateBlocks(pages, posts);
updateJobs();

for (const locale of locales) {
await fs.mkdir(`public/data/posts/${locale}`, { recursive: true });
Expand Down
31 changes: 31 additions & 0 deletions workspaces/cms-scripts/src/jobs-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from "fs/promises";
import * as path from "path";
import YAML from "yaml";
process.chdir(path.resolve(__dirname, "../../.."));

import { yaml } from "./utils";

async function updateJobs() {
const resourceName = "jobs";
const filenames = await fs.readdir(`_data/${resourceName}`);

for (const filename of filenames) {
const filepath = path.join("_data", resourceName, filename);

const data = await yaml(filepath);
const isOlderThanTwoMonths = (dateString: string) => {
const date = new Date(dateString);
const today = new Date();
today.setMonth(today.getMonth() - data.archive_after);
return date < today;
}
const isOlder = isOlderThanTwoMonths(data.published_at);
if (isOlder) {
data.status = "archived";
}
await fs.writeFile(filepath, YAML.stringify(data), {
encoding: "utf8",
});
}
}
updateJobs();
1 change: 1 addition & 0 deletions workspaces/website/src/blocks/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const texts = [
"Servus zu",
];


export const Intro = () => {
const [index, setIndex] = useState(0);

Expand Down
21 changes: 4 additions & 17 deletions workspaces/website/src/pages/jobs/JobsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function JobsPage({ params, env, seo }: Props): JSX.Element | null {
>
<Configure
hitsPerPage={40}
facetsRefinements={{ locale: [params.locale] }}
facetsRefinements={{ locale: [params.locale], status: ['active'] }}
/>
<JobsPageLayout params={params} seo={seo} />
</InstantSearch>
Expand All @@ -65,6 +65,7 @@ export function JobsPage({ params, env, seo }: Props): JSX.Element | null {
}

const JobsPageLayout = ({ params, seo }: Pick<Props, "params" | "seo">) => {

const { items: roles, refine: refineRoles } = useRefinementList({
attribute: "job.role",
sortBy: ["name:asc"],
Expand Down Expand Up @@ -307,6 +308,8 @@ export type JobsHit = {
contact?: Contact; // contact can be undefined in live preview
job?: Job; // job can be undefined in live preview
published_at?: string;
archived?: string;
archive_after: string;
};

function CustomHits() {
Expand All @@ -319,22 +322,6 @@ function CustomHits() {
<JobsCard key={i} hit={hit} />
))}
</Flex>
{/* {hits.map((hit, i) => (
<ArticleCard.Root href="$" key={i}>
<ArticleCard.Image url={`/static/${hit.image}`} />
<ArticleCard.Body>
<ArticleCard.Category category={hit?.category} />
<ArticleCard.Content title={hit.title} excerpt={hit.short_desc} />
</ArticleCard.Body>
<ArticleCard.Footer
postType="audio"
publishedAt="Nov 24, 2022"
duration="1hr 2mins"
/>
</ArticleCard.Root>
))} */}

{!isLastPage && (
<HStack mt="24">
<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default function RoadmapPost({
<div>{roadmapPost?.state ? <Text display="flex" alignItems="center" variant="cardBody" color="roadmap-availability-state-fg" height="32px" borderRadius="5px" padding="4px 12px" borderWidth="1px" borderStyle="solid" borderColor="roadmap-card-border-color" bg="roadmap-card-tag-bg">{roadmapPost?.state}<Box display="inline-block" bg={roadmapPost?.state === "On testnet" ? "#00815C" : "#EF5600"} borderRadius="50%" width="14px" height="14px" ml="2"></Box></Text> : null}</div>
</Flex>
<Divider mt="8px" mb="32px" />

<Flex direction="column" gap="32px">
{roadmapPost.blocks?.map((block, i) => (
<Block
Expand Down

0 comments on commit 79b65a1

Please sign in to comment.